开发者

window.location.href not working in Safari

Why won't this work in Safari?

<script language="javascript" type="text/javascript">
开发者_Python百科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.


Maybe this will work:

<script>
function popitup(url) {
    newwindow=window.open(url,'name','height=200,width=150');
    if (window.focus) {newwindow.focus()}
    return false;
}

// -->
</script>

Then use this HTML:

<a href="popupex.html" onclick="return popitup('popupex.html')">Link to popup</a>


I was able to get it to work in Safari using this code.

if (app.Name == "Safari") {
window.location ="your-url-here"
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜