Javascript 如何使用 HTML 按钮在 HTML 站点中从一个页面重定向到另一个页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13905137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to redirect from one page to another in HTML site using HTML button
提问by Moutasim Momani
Possible Duplicate:
How to make a page redirect using Javascript?
可能的重复:
如何使用 Javascript 进行页面重定向?
i have an HTML pages i want to use to redirect from one page to another like response.redirect in ASP.Net. i think i must use JavaScript.
我有一个 HTML 页面,我想用它从一个页面重定向到另一个页面,例如 ASP.Net 中的 response.redirect。我想我必须使用 JavaScript。
回答by adeneo
<input type="button" onclick="document.location.href = 'http://google.com'" />
or without JS
或没有 JS
<form action="/contact.html">
<input type="submit">
</form>
回答by Gurpreet Singh
In JavaScript you can do:
在 JavaScript 中,您可以执行以下操作:
window.location="http://someplace.com";
or on HTML button do this:
或在 HTML 按钮上执行以下操作:
<input type="button" onclick="document.location='http://someplace.com'" />
回答by Luke
onclick="document.location.href = 'http://google.com'"
OR
或者
onclick="window.location = 'http://google.com'"
Should work fine if you add it into your tag, replacing google with your desired address of course.
如果您将它添加到您的标签中,应该可以正常工作,当然,用您想要的地址替换 google。
回答by valentinas
Or you could use a link styled as a button. If the only thing that button does is redirects to other page, then you should use a link, it would be semantically better.
或者您可以使用样式为按钮的链接。如果按钮所做的唯一事情是重定向到其他页面,那么您应该使用链接,这在语义上会更好。

