JavaScript: closing a window from an iframe

I have a download of a P1 page from an S1 site that contains an iframe. This iframe loads a P2 page from another S2 site. At some point, P2 would like to close the browser window containing the P1 loaded from S1. Of course, since P2 is being downloaded from another site, it cannot just do parent.close ().

I have full control over P1 and P2, so I can add JavaScript code for P1 and P2 as needed. Suggestions on how to resolve this?

0


source to share


4 answers


It's impossible, I'm afraid. JavaScript from an iframe loaded into another site then the one it receives is strictly prohibited due to security concerns.

However, if the iframe is pointing to the same site, you can get it like:



<iframe name = "frame1" src = "http://yoursite">
</iframe>

<script type = "text/javascript">
    alert(window.frames["frame1"].document);
</script>

      

+1


source


If they originated from the same domain, you can change the security restrictions to allow modification between subdomains.

set document.domain = "domain.com"; // on both pages and they are allowed to modify each other.



Maybe it's just setting them to a bogus domain, haven't tried this or just just ".com" or something.

0


source


Looks like this guy got cross-domain JavaScript running between iframes.

0


source


You can use Flash for this. Send the user to a new top-level page that you control with a URLRequest with a _top target, and that page has javascript that does window.close ().

0


source







All Articles