function reDir() {
window.onbeforeunload = null;
window.location = "http://www.google.com";
}
<form target="_blank" onsubmit="reDir()" method="post">
<input type="text" placeholder="Enter Your Email" class="ema" name=email onClick="this.value='';" class=inp value="" style=""><br><br>
<input type="image" src="images/enter.png" alt="Enter" /><br>
</form>
表单在新标签中提交就好了,但我也希望现有标签重定向到google.com,我该怎么做?任何帮助将不胜感激!
答案 0 :(得分:0)
尝试如下。
window.location.href = 'http://www.google.com';
// Sets the new location of the current window.
window.location = "http://www.google.com";
// Sets the new href (URL) for the current window.
window.location.href = "http://www.google.com";
// Assigns a new URL to the current window.
window.location.assign("http://www.google.com");
// Replaces the location of the current window with the new one.
window.location.replace("http://www.google.com");
// Sets the location of the current window itself.
self.location = "http://www.google.com";
// Sets the location of the topmost window of the current window.
top.location = "http://www.google.com";
答案 1 :(得分:0)
setTimeout
和window.location.href
可以解决问题。
function reDir() {
setTimeout(function () {
window.onbeforeunload = null;
window.location.href = 'http://www.google.com';
}, 10);
}
<form onsubmit="reDir()" target="_blank" method="post">
<input type="text" placeholder="Enter Your Email" class="ema" name=email onClick="this.value='';" class=inp value="" style=""><br><br>
<input type="image" src="images/enter.png" alt="Enter" /><br>
</form>