1

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 :)

herteladrian
  • 381
  • 1
  • 6
  • 18

1 Answers1

0

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.

Community
  • 1
  • 1
vooD
  • 2,881
  • 2
  • 25
  • 34
  • Is there any way I can get around this? Can I allow cross-domain access in the permissions in my manifest some how? – herteladrian Jan 20 '14 at 23:59
  • @user1702529 have a look at this wiki http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy – vooD Jan 21 '14 at 00:04
  • Can you provide me with code with which i can access the contents of the iFrame i am creating – herteladrian Jan 21 '14 at 03:30
  • @user1702529 do you have access to the server that iframe points to? – vooD Jan 21 '14 at 06:27
  • No I do not. I am loading ebay links in my iframe. Let me know if you need any more info – herteladrian Jan 21 '14 at 08:12
  • @user1702529 this is not possible then. Please read this answer http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy. What you are really trying to achieve? Maybe there is another way around. – vooD Jan 21 '14 at 08:32