0

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?

5
  • What does e.currentTarget.location.href show? Commented Apr 14, 2019 at 5:16
  • about:blank... but console.log lists the other address in the drop down. Commented Apr 14, 2019 at 5:16
  • What's the actual page URL? Commented Apr 14, 2019 at 5:19
  • the second one. Commented Apr 14, 2019 at 5:19
  • @JasonAxelrod Is the question is related to console values, working as expected? Commented Apr 14, 2019 at 5:56

1 Answer 1

4

The Location is evaluated some time before.

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

Value below was evaluated just now.

Sign up to request clarification or add additional context in comments.

3 Comments

So what is the solution here?
@PrashantPimpale, to me, the solution is to avoid console when possible.
I thought the Jason Getting the first one, that's why posted a question!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.