所以我有一个表格和onsubmit="return reg_check(this)"
其中reg_check()
是一个JavaScript函数的头应该检查表单数据,因为它的任务之一是检查是否用户名是在需要php的数据库中,我想重定向到执行此任务的php页面。window.location.href不工作在窗体上onsubmit
问题是:window.location.href
不工作!这里的功能(缩版),当然还有main.php
只是一个随机的网页,我得到:
function reg_check(myForm) {
alert("before redirect..");
window.location.href = "http://localhost/main.php?width=" + screen.width + "&height=" + screen.height;
alert("after redirect..");
}
的before redirect
和after redirect
警报工作,它只是不重定向?它仍然在同一页面。
另外,如果我试图通过只输入从身体到重定向:
<script type="text/javascript">
alert("before redirect..");
window.location.href = "http://localhost/main.php?width=" + screen.width + "&height=" + screen.height;
alert("after redirect..");
</script>
它重定向。
任何想法,我怎么能得到这个工作?
嗯感谢小费探索细节,但它仍然无法正常工作 – Noura 2011-05-24 11:52:10
@Nara遗憾没我说的没错,我已经更新了答案,你现在应该很好。 – Craig 2011-05-24 11:55:22
啊然后没什么新鲜的。这就是我已经使用 – Noura 2011-05-24 12:01:16