1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

get URL from another Windows generare ti js

Discussion in 'JavaScript' started by Fratozzi, Apr 3, 2021.

  1. #1
    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);
     
    Fratozzi, Apr 3, 2021 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #2
    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.
     
    deathshadow, Apr 3, 2021 IP
  3. Fratozzi

    Fratozzi Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    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
     
    Last edited: Apr 4, 2021
    Fratozzi, Apr 4, 2021 IP