javascript - Get notified when location of opened popup window changed -


i'm implementing external oauth authentication @ webiste. on button click i'm opening popup let's facebook auth page. need know when authentication completed read oauth token , close popup.

click: function () {    var popup = window.open(url, title, '<options>');    popup.onload = function () {        //1. if url contains token - finish oauth authentication        //2. close popup         //but 'onload' doesn't work external domains    }    return false; }, 

when i'm trying access using polling technique i'm hetting following security error:

uncaught securityerror: blocked frame origin "https://some_app_host_not_the_same_as_following.com" accessing frame origin "https://some_auth_host_which_works_with_facebook.com". protocols, domains, , ports must match.

how can achieve this?

if have control on contents of pop-up, handle window's unload event there , notify original window via opener property, checking first whether opener has been closed. note won't work in opera.

window.onunload = function() {     var win = window.opener;     if (win.closed) {         win.somefunctiontocallwhenpopupcloses();     } }; 

since unload event fire whenever user navigates away page in pop-up , not when window closed, should check pop-up has closed in somefunctiontocallwhenpopupcloses:

var popup = window.open("popup.html", "thepopup", ""); function somefunctiontocallwhenpopupcloses() {     window.settimeout(function() {         if (popup.closed) {             alert("pop-up closed");         }     }, 1); } 

if don't have control on contents of pop-up, or if 1 of target browsers not support unload event, you're reduced kind of polling solution in main window. adjust interval suit.

var win = window.open("popup.html", "thepopup", ""); var polltimer = window.setinterval(function() {     if (win.closed !== false) { // !== required compatibility opera         window.clearinterval(polltimer);         somefunctiontocallwhenpopupcloses();     } }, 200); 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -