admin管理员组文章数量:1417070
var Index;
var WeekTable=document.getElementbyId('MapList')
var w = window.open("");
The code above will open a new tab and then run this code:
w.document.writeln('HTML CODE GOES IN HERE FOR THE NEW PAGE');
I want to open this page in the same tab so the user can go back to that they were currently at.
var Index;
var WeekTable=document.getElementbyId('MapList')
var w = window.open("");
The code above will open a new tab and then run this code:
w.document.writeln('HTML CODE GOES IN HERE FOR THE NEW PAGE');
I want to open this page in the same tab so the user can go back to that they were currently at.
Share Improve this question edited Aug 29, 2013 at 19:14 kender 87.4k26 gold badges105 silver badges146 bronze badges asked Aug 29, 2013 at 19:09 user2722517user2722517 393 silver badges12 bronze badges 3-
1
Do you mean open a new tab in the same window? So you want
window.open
to force open a new tab instead of window? – Travis Commented Aug 29, 2013 at 19:10 - 1 So, you want to redirect them to a new page? – gen_Eric Commented Aug 29, 2013 at 19:11
- window.open will open a new tab. I want to do the same thing but keep the user in the same tab so they can go back to the previous page – user2722517 Commented Aug 29, 2013 at 19:13
2 Answers
Reset to default 3... This seems weirdly trivial, but if you just want to redirect the user to a new page in the same tab, get rid of all your JavaScript and use a plain old <a>
tag, where the href
is set to the URL you want to go to. What you're describing is exactly the behaviour you get from a dead simple link, so I'm not sure why you don't just use one:
<a href="/mypage.html">Click Here</a>
If you have to run some JavaScript first, bind to the link's click
event, and then don't return false or run event.preventDefault()
inside your event handler, and the link will still be followed by the browser after your event handler is done.
If you must to do the actual "redirection" in JavaScript for some reason, assign the URL to window.location
instead of using window.open
:
window.location = "http://mysite./mypage.html"
From my understanding,since you want to carry the data from the previous page to the new page,it could be a good idea to store the required variables in a Javascript data structure that you can access later when the new page is loaded. You can create an array and push the data into it,and when you load the new page you will be able to access the required data.
本文标签: htmlJavascript to open new window in the same tabStack Overflow
版权声明:本文标题:html - Javascript to open new window in the same tab - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745259474a2650288.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论