简体   繁体   English

访问iFrame的内容时出错

[英]Error accessing contents of iFrame

I am trying to load several links in a hidden iFrame, one after the other but an error occurs at this line 我试图在隐藏的iFrame中加载多个链接,一个接一个,但此行出现错误

frame.contentDocument.getElementsByClassName('radiopad')[0].getElementsByTagName('input')[0].checked = true;

that states: 声明:

Uncaught TypeError: Cannot call method 'getElementsByTagName' of undefined 

Essentially, I want to load a link in the iFrame, then fill the form on that page that loads in t and submit it(this code is tested and working) and then, once this has been completed, move on to doing the same thing with the next link. 本质上,我想在iFrame中加载链接,然后在加载t的页面上填写表单并提交(此代码已经过测试并且可以正常工作),然后,一旦完成,就继续做同样的事情下一个链接。 I am just currently not able to get the "document"(not sure if that is what is called) of the iFrame. 我目前无法获取iFrame的“文档”(不确定是否是所谓的)。

Here is my entire code snippet in case you need it. 如果需要,这是我的整个代码段。

frame = document.createElement('iframe');
frame.style.display = 'none'
document.body.appendChild(frame);
for (var i = 0; i < feedbackLinks.length; i++) {
    frame.setAttribute('src', feedbackLinks[i]);
    console.log(frame.contentDocument);
    while (frame.src != 'http://feedback.ebay.com/ws/eBayISAPI.dll') {
        frame.contentDocument.getElementsByClassName('radiopad')[0].getElementsByTagName('input')[0].checked = true;
        frame.contentDocument.getElementById('comment00').value = 'Great Seller';
        var starRatings = ['v4-15', 'v4-27', 'v4-32', 'v4-37'];
        for (var ID = 0; ID < starRatings.length; ID++) {
            if (frame.contentDocument.getElementById(starRatings[ID]) != null) {
                frame.contentDocument.getElementById(starRatings[ID]).click();
            }
        }
        frame.contentDocument.getElementById('but_formSave').click();
    }
    console.log("completed link " + (i + 1));
}

Thanks in advance :) 提前致谢 :)

I think your iframe points to different domain. 我认为您的iframe指向其他域。 You have same-domain policy violation . 您有违反同域策略的行为

The policy permits scripts running on pages originating from the same site. 该策略允许脚本在源自同一站点的页面上运行。

Please read this wiki . 请阅读此Wiki It has extended answer to your problem. 它扩展了您的问题的答案。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM