简体   繁体   中英

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

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. I am just currently not able to get the "document"(not sure if that is what is called) of the 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. You have same-domain policy violation .

The policy permits scripts running on pages originating from the same site.

Please read this wiki . It has extended answer to your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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