Jason Axelrod
Jason Axelrod

Reputation: 7815

Javascript window.location returning two different values?

I am using a JS popup window for an Oauth2 Implicit Grant. I'm using JS to monitor for URL changes to get the code grant.

    newWindow.addEventListener('unload', function(e)
    {
        console.log(e.currentTarget.location);

        if (e.currentTarget.location.href.includes('code='))
        {
            var url = new URL(e.currentTarget.location.href);
            alert(url.searchParams.get('code'));
        }
    });

The problem I am having is that the location field is giving two different values for the href parameter.

enter image description here

As you can see in the image, the href parameter has two different values. How do I make sure I always get the second value?

Upvotes: 0

Views: 150

Answers (1)

Mamun
Mamun

Reputation: 68933

The Location is evaluated some time before.

If you hover over the little blue i icon, it says:

Value below was evaluated just now.

Upvotes: 4

Related Questions