当访问者点击按钮元素时,我该如何更改URL?
示例:
示例:
<form id="search">
<input type="text" />
<button onclick="javascript:alert('hi');">Alert Hi</button>
<button onclick="javascript:window.location.href='http://www.google.com/'">Go to Google</button>
</form>
(或查看JSFiddle。)
对于一个快速的演示页面,我只需要在访问者点击按钮时将其重定向到新的URL。我可以通过JavaScript onclick(在Alert Hi按钮中)执行,如果我从Firebug的控制台执行window.location.href='http://www.google.com/'
,则URL会更改。我需要怎么做才能在按钮点击时更改URL?
X-frame-options
。 - Musa