Get Previous Page URL via JavaScript after window.open - javascript

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?

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

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".

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.
​

Related

How to Opeen a parent window while opening a new window

I want to close the parent window when a new window is opened.
I tried top.window.close() but it did not work for me.
Does anybody here know any other method to get a collection of windows
assume, you have a page called "PageA", in "PageA" you can open "PageB" , by this window.open like window.open("PageB") and in "PageB" you can access the window object of "PageA by this window.opener, and to close "PageA" from "PageB" you can use this window.opener.close(), to see complete window.open sample, read this Window.open API
and to review window.opener see this Window.opener API

Get previous page URL, Open New Window, then Redirect through Javascript

I'm stuck using a CMS that only gives me the ability to modify the content of the <body>, so when I want to redirect people, I've used this
<script type="text/javascript">
window.location = "http://www.example.com/"
</script>
So, yes, the page loads first, and then 5ms later, the redirect happens, and it's worked for all intensive purposes. Now, I'm wondering if I can use javascript to do something else.
Is it possible to open a new browser tab, with a specified URL, and then redirect the user back to the previous page, through Javascript?
Many thanks, SO.
EDIT - Whether it opens a new window or tab, to be honest, is not as important as it actually functioning. I need Javascript to determine the prior page (if possible), then open a new window/tab to a URL I specify, and then redirect the current window/tab to it's prior page. Some are saying that window.open only works on a click event, which will not work for what I am trying accomplish either... just fyi.
So, literally, without clicks, I need Javascript to do the following -
Determine the prior/previous/last page the user came from, store it as a variable
Open a new window or tab, to a specified URL
window.location back to the prior page, which I stored as a variable
Hope that makes sense.
Depending on the user's browser setting using window.open can open the new window in a new tab instead but you CANNOT directly control this through the browser. It is all down to the user's settings.
To open a new window:
window.open("http://www.google.com", "windowName", "window options (optional parameter)");
Then simply use:
history.back();
You can also use the referer property:
var previousUrl = document.referrer;
For more info on window.open, see: http://www.javascript-coder.com/window-popup/javascript-window-open.phtml
For more info on the document.referrer property, take a look at: http://www.netmechanic.com/news/vol4/javascript_no14.htm

Open link in new window using javascript?

i tried below javascript and it does open the url in open window but it clears the url in the current window as well points to the new URL.
window.open('http://www.google.com','_blank');
This is occurring because the second spot where you have _blank is where the name should be.
I would recommend as the link above that Nathan post suggests doing this. :
window.open(url, windowName, "height=200,width=200");
Then doing some javascript triggering on whatever event is causing the new window to open.
So, lets say it is an image, set the Target="_blank" for the image and then set an OnClick event to call a function with the window.open code in it.
That will do the trick. HTH

JavaScript Bookmarklet to open new Window and transmit params of origin Page

I have a perfectly working bookmarklet to grab the Document-Title and the URL of the current Website and place it into the URL of the new loaded Page (Code below) … now I wonder how to let this domain.com/bookmarklet?… open in a new small window (600x600px), so that I still see the old website from where I grabed the title and url in the background and have the new page (domain.com/bookmarklet?…) in the foreground.
javascript:location.href='http://domain.com/bookmarklet?url='+encodeURIComponent(location.href)+';title='+encodeURIComponent(document.title)
How can I achieve that?
Use window.open(...) instead of setting location.href = ....
you need to use window.open() for that
javascript:window.open ("http://domain.com/bookmarklet?.......","MyBookmarklet");

link to itunes (itms://...) without opening a new window

how do i call a link to itunes (itms://...) without opening a new window.
with window.open there comes a new window (as the function says :))
$.get('itms://...'); doesn't work.
Any other possibilitys :)?
would be thankful for help!
Didn't try, but two ideas come to mind:
iframe
set location to the URL, it shouldn't replace your page anyway.
To clarify, you are referring to not opening a new browser window, as opposed to trying to open iTunes within the browser.
In that case, Nickolay's 2nd option is your best bet - this JavaScript will work (using actual example URL):
var url = 'itms://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=307538288';
location.href = url;

Categories

Resources