1

If I have a script which calls window.open, loading a new page into the same window, then that new page's JavaScript needs to identify the Previous Page's URL - what is the best way to find it?

3 Answers 3

3

You can use window.opener.location.href , it will give you the URL of the parent page from which you opened a new window.

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

Comments

0

You can use window.opener to obtain a reference to the window that opened the current window. Not sure if this is what you are after. When using window.open it will result in a new window, not sure what you mean by "open new window in the same screen".

2 Comments

we can open new screen in the same window like window.open("About.html", '_self'). And in the new screen i want the previous page url.
Can you pass a parameter to the new page?
0

Using Window.opener you can get it, like

var win=​window.open('http://heera.it')​;
console.log(win.opener.location.href); // will output the url

Example.

1 Comment

Actually i want to open new screen in the same window itself by using window.open("About.html", '_self'). so after this when i use window.opener.location.href is not giving any value

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.