开发者

Issues using window.opener in all browsers

Okay, I'm having serious problems here. On my own computer, this code works just fine. But on my coworkers, it breaks in IE and Firefox.

var openlocation = window.opener.location.href;

breaks for "Permission Denied", on the window.opener part. So, on the opener page, I wrote a function that's stored in an external .js page:

var getLocation = function() {
    return window.location.href;
};

and then calling that, like var openlocation = window.opener.getLocation();

Does anyone have any idea why this is breaking?

Edit: One page is creating the popup, and they're both on the same domain. The popup page has the following code:


$(document).ready(function () {
    var openlocation = window.opener.getLocation();
    (function setTimer() {
        setInterval(function () {
            if (window.opener.location.href != openlocation) {    // they've changed screens
                window.close();
            }
        }, 15000);
    })();
  $("input#notescancel").click(function () {
        window.close();
  });
});

I've tried with both my getLocation() function and just using window.opener.location.href but, for all computers but mine, it breaks. 开发者_StackOverflowThanks.


It may be because that the 2 windows are on different domains. Even sample.com and www.sample.com are considered different by the browser. Technically its called Same Origin Policy,

https://developer.mozilla.org/en/Same_origin_policy_for_JavaScript


I figured it out. I was going to deep into window.opener.location - for IE, I should stop it there, convert it to a string, and call it good. Which is what I did, and it now works.

So, instead of window.opener.location.href, I just used window.opener.location.toString() for IE.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜