My website (Site 1) launches a window with the URL from another website (Site 2). I can modify the code in either website, but they have differen domain names.
The page I am launching in Site 2 has the following code, which refeshes the page that opened it when the close button is clicked.
window.opener.parent.document.forms[0].submit();
Works fine when the page is launched from within Site 2, but from Site 1, gives the following Javascrip开发者_Python百科t error, due to the differing domains:
Permission Denied To Get Window.document
Is there some way of checking, in Javascript, whether I have access to the opener's document? I'd like to retain the refreshing functionality within Site 2, but without causing errors in Site 1.
I'm hoping that there is something like this I can write:
if (I have access to window.opener.opener.parent.document)
{
window.opener.opener.parent.document.forms[0].submit();
}
Have you tried the Try/Catch construct of JS (http://www.w3schools.com/js/js_try_catch.asp)?
精彩评论