JavaScript重定向表单提交
JavaScript redirect on form submission
我正在尝试做一个练习,允许用户根据他们的搜索词被重定向到特定的本地网页。由于某些原因,window.location.replace不会重定向。我尝试了window的一种变体。在新标签页中打开登陆页的位置,这是有效的。任何帮助都是感激的!
html<form name="form1" onsubmit="myFunction()">
Street Address:
<input type="text" id="streetaddress" required="true"><br>
Township:
<input type="text" id="township" required="true">
<br>
<input type="submit" onclick="return myFunction()" name="Search" value="Search">
</form>
<p id="demo"></p>
js
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "";
var nameValue1 = document.getElementById("streetaddress").value;
var nameValue2 = document.getElementById("township").value;
if (nameValue1.toUpperCase() === "1 MARJORAM DRIVE" && nameValue2.toUpperCase() === "LUMBERTON") {
window.location.replace("landingpage.html");
}
else {
document.getElementById("demo").innerHTML = "<font color='red'><p>0 results</p></font>";
return false;
}
}
</script>
我已经修改了我的代码实现建议的解决方案,但我仍然遇到同样的问题,页面不会重定向。我从原始代码中更改的行如下…
html<form name="form1" onSubmit="return myFunction()">
<input type="submit" name="submit" class="submit" value="Search">
js
if (nameValue1.toUpperCase() === "1 MARJORAM DRIVE" && nameValue2.toUpperCase() === "LUMBERTON") {
window.location.href = 'landingpage.html';
}
修改window.location
变量
window.location = "http://www.newsite.com/path/to/page";
对于本地托管的页面,使用以下命令:
window.location.href = "newlocation.html";
相关文章:
- 张贴HTML表单后重定向
- Javascript验证表单不重定向页面
- 防止 javascript 在发送表单后重定向页面
- 提交表单后重定向页面
- 提交AJAX表单,重定向而不是在页面上处理
- 表单提交重定向到新网址
- 提交表单后重定向(HTML,PHP)
- 成功提交表单后重定向用户
- 如何在php中提交表单后重定向
- 表单onsubmit重定向导致表单未提交
- 将详细信息发送到数据库后,正在将表单提交重定向到URL
- 设置单选按钮单击两个目的地(提交表单和重定向)
- ajax表单提交重定向类似于非ajax表单
- Jquery提交表单然后重定向不工作
- 在用户提交表单后重定向用户
- jQuery Mobile -提交表单,重定向到页面id
- 表单提交重定向不工作使用联系人表单7 WordPress插件
- pjax提交表单URL重定向
- 提交多个表单后重定向
- 在Javascript中提交表单后重定向