window.location.href在Safari中不起作用 [英] window.location.href not working in Safari

查看:1211
本文介绍了window.location.href在Safari中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么不能在Safari中使用?

 < script language =javascripttype =text / javascript > 
函数changeUrl(url){
window.location.href ='http://google.com';
返回false;
}
< / script>

< form action =#onsubmit =changeUrl(this)/>
< input type =Submitvalue =Go/>
< / form>


解决方案

Safari似乎不喜欢在函数调用。如果您将其移入您的onsubmit中,则为onsubmit =openPop(this.action); return false;那么Safari就会毫无问题地工作。编辑:为了改进答案,onsubmit本身需要返回false,所以openPop返回false是不够的。你可以让它做onsubmit =return openPop(this.action);尽管如此。


Why won't this work in Safari?

<script language="javascript" type="text/javascript">
function changeUrl(url) {
  window.location.href='http://google.com';
  return false;
}
</script>

<form action="#" onsubmit="changeUrl(this)" />
  <input type="Submit" value="Go" />
</form>

解决方案

Safari appears to dislike having the return false occur in the function call. If you move it into your onsubmit as onsubmit="openPop(this.action);return false;" then Safari will work without issue.

Edit: To improve the answer, onsubmit itself needs to return false, so openPop returning false is not enough. You could just have it do onsubmit="return openPop(this.action);" though.

这篇关于window.location.href在Safari中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆