admin管理员组文章数量:1391937
I need to setup a form on my site which will enable people to quickly navigate to a page by typing a number into a form and clicking 'go'.
I've got the following code which works in part:
<script type="text/javascript">
function goTo()
{
window.location = document.forms[0].where.value ;
return false;
}
</script>
</head>
<body>
<form action="" method="post" onsubmit="return goTo()">
<input type="text" name="where" value="Enter page number" onfocus="if(this.value == this.defaultValue) this.value = '';" onblur="if(this.value == '') this.value = this.defaultValue;">
<input type="submit" value="Go">
</form>
</body>
</html>
I'm injecting this code onto a page with a url, for example, like:
www.examplesite/navigate
The form appears just fine on the /navigate page. Now I'd like my users to be able to type a number into the form which corresponds to a url on my site. For example to get to:
www.examplesite/1234
the user would type '1234' into the form and press 'Go'.
What's happening instead however is the page the script is trying to open is:
www.examplesite/navigate/1234
Does anyone have any idea how I could modify the script to ensure it always opens a page at the root of the site rather than a subdirectory?
Thanks in advance for any help. Appreciate it.
I need to setup a form on my site which will enable people to quickly navigate to a page by typing a number into a form and clicking 'go'.
I've got the following code which works in part:
<script type="text/javascript">
function goTo()
{
window.location = document.forms[0].where.value ;
return false;
}
</script>
</head>
<body>
<form action="" method="post" onsubmit="return goTo()">
<input type="text" name="where" value="Enter page number" onfocus="if(this.value == this.defaultValue) this.value = '';" onblur="if(this.value == '') this.value = this.defaultValue;">
<input type="submit" value="Go">
</form>
</body>
</html>
I'm injecting this code onto a page with a url, for example, like:
www.examplesite./navigate
The form appears just fine on the /navigate page. Now I'd like my users to be able to type a number into the form which corresponds to a url on my site. For example to get to:
www.examplesite./1234
the user would type '1234' into the form and press 'Go'.
What's happening instead however is the page the script is trying to open is:
www.examplesite./navigate/1234
Does anyone have any idea how I could modify the script to ensure it always opens a page at the root of the site rather than a subdirectory?
Thanks in advance for any help. Appreciate it.
Share Improve this question asked Jun 18, 2013 at 9:15 user2471356user2471356 11 silver badge1 bronze badge1 Answer
Reset to default 8Try this:
window.location = "/" + document.forms[0].where.value ;
/
means root. Without it the path is relative to current folder.
In some cases you can use base
tag, have a look: https://developer.mozilla/en-US/docs/Web/HTML/Element/base
本文标签: javascript 39go to page39 form scriptStack Overflow
版权声明:本文标题:javascript 'go to page' form script - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744730873a2622039.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论