I have this problem, I can't get the url of a window I open. If I use window.location I get the result, but when I execute window.location.origin or others, nothing comes back to me, what can I do? I see the error in catch and its a message : domexception: permission denied to access property "document" on cross-origin object I work in local with xampp, maybe It this the problem... Can u Help me pls var win = window.open(popupurl, "authwindow", 'width=800, height=600'); var pollTimer = window.setInterval(function () { try { if (win.document.URL.indexOf(CLIENT_REDIRECT) != -1) { window.clearInterval(pollTimer); deffer.resolve(CODE); win.close(); } } catch (e) { } }, 500);
Cross-origin access aresomething that are supposed to be blocked between browser windows/tabs. It is one of many reasons that window.open is more a relic of the past than a modern development technique, and if possible I'd avoid using it altogether just like you would/should iframes. (which are limited these days pretty much to adverts and things like codepen) You also have to deal with how some browsers block and/or offer blocking of scripting being allowed to open windows, and/or not allowing you to set width/height or have them as separate windows, instead making them tabs. That's why these days when possible we use modal dialogs with AJAX to accomplish these sorts of tasks. Assuming you have control of whatever your "popupurl" is loading, that's the approach I would recommend. Do yourself a favor, and forget window.open even exists.
thank you very much for your reply, I have tried all ways but I can't get what I want. if I use that script it works halfway. can you help me convert it using Ajax? what i need to do is this, i need to get a user's permission to use data on google fit. moreover I must allow to revoke the authorization and also to refresh the token if it has expired. with that script I can authorize the user and get the code that google generates with auth2, but since I open it with another window, I can't get the answer in the form of get url. Thanks again