admin管理员组文章数量:1303647
I want to relocate on button click to a relative url:
<button onclick="document.location.href='/Recruiters.aspx'"></button>
but this is not working...
Any suggestions?
I want to relocate on button click to a relative url:
<button onclick="document.location.href='/Recruiters.aspx'"></button>
but this is not working...
Any suggestions?
Share Improve this question asked Apr 15, 2013 at 13:13 David Van StadenDavid Van Staden 1,7899 gold badges35 silver badges52 bronze badges 4-
1
Try with
window.location.href
. – Brugnar Commented Apr 15, 2013 at 13:17 - Is the button inside a form? – Esailija Commented Apr 15, 2013 at 13:18
- @Brugnar...nope does not work – David Van Staden Commented Apr 15, 2013 at 13:26
-
@DavidVanStaden
window.location.href
wouldn't fix it, but it's preferred overdocument.location.href
– Ian Commented Apr 15, 2013 at 13:30
2 Answers
Reset to default 6The default type
of a button is "submit"
so when inside a form, clicking the button submits it. Though it should first redirect but it's worth a shot:
<button type="button" onclick="document.location.href='/Recruiters.aspx'"></button>
Your onclick needs to be a handler. You could do it like this:
<script>
function redirect()
{
window.location.href='/Recruiters.aspx';
}
</script>
<button onclick="redirect()"></button>
If you don't want to use a handler you can still do it inline like this:
<button onclick="javascript: window.location.href='/Recruiters.aspx';"></button>
本文标签: javascriptdocumentlocationhref for relative pathStack Overflow
版权声明:本文标题:javascript - document.location.href for relative path - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741770292a2396709.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论