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.locationback to the prior page, which I stored as a variable
Hope that makes sense.
Depending on the user’s browser setting using
window.opencan 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:
Then simply use:
You can also use the referer property:
For more info on
window.open, see: http://www.javascript-coder.com/window-popup/javascript-window-open.phtmlFor more info on the document.referrer property, take a look at: http://www.netmechanic.com/news/vol4/javascript_no14.htm