[英]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&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.