[英]window.location() not working, not opening page
我有一个带有 onClick 的提交按钮:
<div id="messageDiv">
<form>
<textarea name="message" rows="10" cols="20"></textarea></textarea>
<br /><br />
<input type="submit" value="Send" onClick="sendmail()">
<input type="reset" value="Reset" name='reset'>
</form>
</div>
然后我有我的sendmail:
function sendmail()
{
window.location.href = "http://www.rainbowcode.net/index.php/profiles/mail?="+mailid;
window.location('http://www.rainbowcode.net/index.php/profiles/mail?='+mailid);
//return true;
}
mailid
是在另一个 JS 函数中设置的全局变量,它确实包含正确的值。 window.location
怎么window.location
我的页面?
如果我用mailid手动打开它,它工作正常..
设置位置工作正常,但随后提交表单,这将重新加载当前页面。
从方法返回 false:
function sendmail() {
window.location.href = "http://www.rainbowcode.net/index.php/profiles/mail?="+mailid;
return false;
}
并在事件中返回该状态以停止提交:
<input type="submit" value="Send" onclick="return sendmail()">
我花了 2 天时间尝试此处和其他地方显示的所有解决方案,但无济于事。 然后我删除了form
标签,因为没有submit
按钮,所以没有用,问题消失了:
window.location = 'mypage.php', true;
如果你需要打开一个新窗口,你应该使用window.open()方法。 window.location指的是当前窗口地址,并且只会 - 当使用window.location.reload()
- 重新加载当前窗口。
尝试使用replace
功能
window.location.replace('http://www.rainbowcode.net/index.php/profiles/mail?='+mailid)
已经有了可靠的答案,但为什么要与系统作斗争呢? 特别是如果您使用 jquery 或onClick
调用-我的观点可能没有内联返回-因此您可以更改submit
的操作:
document.form.action = 'http://www.rainbowcode.net/index.php'
那么您可以根据需要选择任何表单变量,否则可以忽略。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.