最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - button javascript works on IE but not firefox window.navigate() - Stack Overflow

programmeradmin4浏览0评论
<input type="button" value="Back" onClick="window.navigate('')">

This works on IE8, but not firefox or opera. Anyone know why and how to fix it?

<input type="button" value="Back" onClick="window.navigate('http://www.google.com')">

This works on IE8, but not firefox or opera. Anyone know why and how to fix it?

Share Improve this question edited Sep 10, 2013 at 5:51 iceheaven31 8871 gold badge14 silver badges24 bronze badges asked Jul 10, 2009 at 21:31 Ian McCulloughIan McCullough 1,4434 gold badges25 silver badges36 bronze badges 0
Add a comment  | 

6 Answers 6

Reset to default 10

If you check the documentation for that method, you will see the quite common:

There is no public standard that applies to this method.

This means that it's a non-standard feature that most likely only works in Internet Explorer.

This will work:

<input type="button" value="Back" onclick="window.location.href='http://www.google.com';">

If you are using XHTML:

<input type="button" value="Back" onclick="window.location.href='http://www.google.com';" />

.navigate() only works in IE.

Try setting the window.location.

window.location.href = 'http://www.google.com'
<a href="http://www.google.com">Google</a>
  • links want to be links
  • links afford navigation, buttons afford actions. This is navigation
  • depending on JS is a bad idea

… and "back" is a poor choice of link text. Either a link or your IE specific JS will take the user forward. It will add a URL to the end of the user's history. It won't activate the browser's Forward functionality.

<input type='button' value='click' onclick="window.location='http://google.com';" />

For searchers on this problem: Ensure your input not post to current page like sumbit. In this case any navigate methods will not work. To fix this add event.preventDefault() on click handler

window.navigate is a non-standard Internet Explorer feature. Other browsers simply don't provide the function.

You could shim it with:

if (! window.navigate) {
    window.navigate = function (arg) {
    location.assign(arg);
   } 
}  

… but your code would be better if you just rewrote it to use standard methods (i.e. the location object) in the first place.

Reference: https://stackoverflow.com/a/28793432/6737444

发布评论

评论列表(0)

  1. 暂无评论