11

I have a plugin which records user action on any website. The actions are recorded in a different window of the same browser. For IE, it works properly on all sites except the ones having Iframe. The script gets blocked on the sites having Iframes with the following error: SCRIPT5: Access is denied.

Its a self created plugin.

The error is on window.open It does not open a new window properly

Below is the snippet of the plugin.

newwindow = window.open("", "ScriptGen", "menubar=0,directories=0,toolbar=no,location=no,resizable=yes,scrollbars=yes,width=450,height=250,titlebar=0"); 

newwindow.document.write('<title>New Console</title>');

Using alert(window) displays "[object Window] on all sites..but on sites having iframes, it displays only "[object]"

Please guide.

7
  • To start off with, what's the name of the plugin? Commented May 15, 2015 at 7:21
  • Its a self created plugin. Commented May 15, 2015 at 9:26
  • IE? is it on every version of it or some specific versions? Commented May 18, 2015 at 7:22
  • 2
    yes... it's called same origin policy. basically if the page ins't on the same domain/url path you can't touch it or do anything with it. The only way you could do something with it is with a behind the scenes proxy. ternarylabs.com/2011/03/27/… or use a solution like staticapps.org/articles/cross-domain-requests-with-cors Commented May 18, 2015 at 7:23
  • I tried both but its not working,I am not able to access nethng from the newwindow,Neither changing domain of the original window works.Is there any other solution? Commented May 18, 2015 at 12:23

3 Answers 3

3
+25

I don't know what version of jQuery are you using, but I think you should update to 1.11.0:

https://jsfiddle.net/j3LaC/ - try this with 1.10.1 (not working), and with 1.11.0 (working)

HTML:

<div id="body"></div>
<input id="button" type="button" value="Submit iframe"/>

JavaScript:

var iframe = $("<iframe></iframe>").appendTo("#body")[0];
var doc = iframe.document;
var content = '<form method="get"><input name="hidden" type="hidden" value="123"/></form>';
doc = iframe.contentDocument;
doc.writeln(content);
doc.close();

$('input#button').click(function () {
    $('iframe').contents().find('form')[0].submit();
});

CSS:

iframe {
    height: 300px;
    width : 100%;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your reply...I tried it but even this doesnt seem to solve my problem...
0

Banish the iframes before running your plug-in

function banish() {
    $('iframe').remove();
}

Comments

0

This worked for me...

try{
           newwindow = window.open("", "ScriptGen", "menubar=0,directories=0,toolbar=no,location=no,resizable=yes,scrollbars=yes,width=450,height=250,titlebar=0");
            console.log(newwindow.document);
        }
        catch (error) {
            console.log("Error catched");
            newwindow.close();
            useDomain = true;
            var domain = document.domain;
            newwindow = window.open("javascript:document.write('<script>document.domain=\"" + document.domain + "\"</script>')", "ScriptGen", "menubar=0,directories=0,toolbar=no,location=no,resizable=yes,scrollbars=yes,width=450,height=250,titlebar=0");
    }

Thank you everyone for your help.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.