简体   繁体   English

从javascript获取所有uid时出错

[英]Error while getting all the uid from javascript

In the facebook pokes page ie http://www.facebook.com/pokes I am trying to find all the uid using javascript. 在facebook戳页面(即http://www.facebook.com/pokes)中,我正在尝试使用JavaScript查找所有uid。 From firebug i get the tag name which is following... 从萤火虫我得到下面的标签名称...

<a rel="async-post" ajaxify="/ajax/pokes/poke_inline.php?uid=XXXXXXXXXXXX&amp;pokeback=1" href="#" class="uiIconText"><i style="top: 0px;" class="img sp_1lbo22 sx_3b5b96"></i>Poke Back</a>

在此处输入图片说明

To get all the uid, i designed my javascript in following manner- 为了获得所有的uid,我以以下方式设计了我的JavaScript:

var allAnchorElements = document.getElementsByTagName('a');

for (var i = 0; i < allAnchorElements.length; i++) {
   var uid = allAnchorElements[i].ajaxify.match(/uid=([0-9]*)/)[1];

I haven't put the complete code here. 我没有把完整的代码放在这里。 Now when executing this code from firebug console, i am getting TypeError: allAnchorElements[i].ajaxify is undefined error. 现在,当从firebug控制台执行此代码时,我收到TypeError: allAnchorElements[i].ajaxify is undefined错误。

Why i am getting this error? 为什么我收到此错误? How can i change my script to get all uid? 如何更改脚本以获取所有uid?

Well document.getElementsByTagName('a'); 好document.getElementsByTagName('a'); is getting all of the links on the page. 正在获取页面上的所有链接。 Do all of the links have that attribute? 所有链接都具有该属性吗? If the answer is no, filter them out. 如果答案是否定的,请过滤掉它们。

One way: 单程:

var allAnchorElements = document.getElementsByTagName('a');
for (var i = 0; i < allAnchorElements.length; i++) {
    var ajaxify = allAnchorElements[i].ajaxify;
    if (!ajaxify) {
        continue;
    }
    var uid = ajaxify.match(/uid=([0-9]*)/)[1];
}

Another way would be to use a querySelector to get the elements. 另一种方法是使用querySelector获取元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从JavaScript中的套接字获取消息时出错 - Error while getting messges from sockets in javascript 从mongodb集合中获取所有文档时出错 - Getting error while fetching all documents from a mongodb collection 从Selenium运行javascript时出现“参数未定义”错误 - Getting “argument is not defined” error while running the javascript from Selenium 将值从javascript传递到jsp中的scriplet时出错 - getting error while passing value from javascript to scriplet in jsp 尝试从Java类访问javascript时出现错误 - Getting an error while trying to access javascript from a java class javascript缩小时出现stackoverflow错误 - Getting stackoverflow error while javascript minification 在遍历数组时遇到JavaScript错误 - getting javascript error while iterating through array 从javascript发送http请求时,获取500:内部服务器错误作为来自Web服务器的响应 - Getting 500: Internal Server Error as a response from webserver while sending http request from javascript 从Dropdown获取价值时Javascript无法正常工作 - Javascript not working while getting value from Dropdown 尝试在Visual Studio中从JavaScript调用插入值到SQL Server时出现内部服务器错误500 - Getting a internal server error 500 while trying to call insert values from javascript into sql server in visual studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM