admin管理员组文章数量:1335412
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 = "/"
</script>
So, yes, the page loads first, and then 5ms later, the redirect happens, and it's worked for all intents and 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 acplish 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.
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./"
</script>
So, yes, the page loads first, and then 5ms later, the redirect happens, and it's worked for all intents and 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 acplish 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.
Share Improve this question edited Feb 5 at 12:31 CommunityBot 11 silver badge asked Nov 15, 2012 at 15:50 RCNeilRCNeil 8,77912 gold badges44 silver badges62 bronze badges 8-
window.open
might be what you are looking for. It's not new tab but might be what you are looking for. – clentfort Commented Nov 15, 2012 at 15:51 - before you spend much time troubleshooting with window.open, remember that it can only be executed from a user action such as a mouse click. – Salketer Commented Nov 15, 2012 at 15:54
-
so, in that regard, can I have
window.open = "http://www.example."; window.location = priorpage;
and then use javascript to determine whatvar priorpage
would be? – RCNeil Commented Nov 15, 2012 at 15:54 - ooops.... good call then @Salketer – RCNeil Commented Nov 15, 2012 at 15:55
- see this question on SO – didierc Commented Nov 15, 2012 at 15:55
1 Answer
Reset to default 3Depending 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.", "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./window-popup/javascript-window-open.phtml
For more info on the document.referrer property, take a look at: http://wwwmechanic./news/vol4/javascript_no14.htm
本文标签:
版权声明:本文标题:Get previous page URL, Open New Window, then Redirect through Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742388855a2465584.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论