admin管理员组文章数量:1332389
I am using this to open on a new window:
<div class="backbutton" OnClick="javascript: window.open('')">Go back</div>
How to amend this if I want onclick to open a hyperlink on the same page?
thanks.
I am using this to open on a new window:
<div class="backbutton" OnClick="javascript: window.open('http://www.goesback.')">Go back</div>
How to amend this if I want onclick to open a hyperlink on the same page?
thanks.
Share asked Jan 12, 2012 at 16:59 user1065673user1065673 931 gold badge1 silver badge5 bronze badges6 Answers
Reset to default 1You just set the url to the window.location.href
so
<div class="backbutton" OnClick="window.location.href = 'http://www.goesback.'">Go back</div>
But you should really just convert it to a regular link
<a class="backbutton" href="http://www.goesback.">Go back</div>
location.href='http://www.goesback.'
Though you might want to reconsider using onclick
to trigger that.
Why not just use a simple anchor tag?
<a href="[where you want to go]">Go There</a>
If you need to use JavaScript, the other answers - setting the window.location
property - will do what you want.
The second parameter of window.open() is a string representing the name of the target window.
Set it to: "_self".
<div class="backbutton" OnClick="javascript: window.open('http://www.goesback.','_self')">Go back</div>
Set the window.location.href
property:
<div class="backbutton" OnClick="window.location.href='http://www.goesback.'">
Go back
</div>
Or just use a plain old anchor
(probably your best option):
<a href="http://www.goesback.">Go back</a>
Note: the javascript:
prefix is not needed in the onclick
handler.
<div class="backbutton" OnClick="window.location.href = 'http://www.goesback.'">Go back</div>
本文标签: How to open a hyperlink on the same page with javascriptStack Overflow
版权声明:本文标题:How to open a hyperlink on the same page with javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742291004a2447794.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论