"window.location.history.go(-2)" possible in major browsers?
As the title says, will this code work and will it work in major 开发者_Python百科browsers?
I ask because currently I have no resources to test it, so I would appreciate some help on this.
Here is what I have (not tested):
setTimeout(window.location.history.go(-2), 5000);
Thanks
setTimeout(window.location.history.go(-2), 5000);
history
is a property of window
, not location
. Also if you want it to trigger after a delay you will need to make a delayed-call function—currently you are calling go()
immediately, and passing the return value of the function to setTimeout
, which clearly won't work. You probably mean:
setTimeout(function() {
history.go(-2);
}, 5000);
As for ‘go back two pages’, yes, it'll work in pretty much all JS-supporting browsers, but it's the kind of thing users are likely to find incredibly confusing. Are you sure you want to do that?
as you can see here this is supported by all browsers for a long time (since ff1.0 / opera 5 / ie 3).
It works on Netscape 2.0+, IE3+, Opera 5.12+, Firefox 1+, Konquerer 3.1+, Safari 1+. You just have to be sure, there are at least so many sites in the history, you want to go back.
German reference on SELFHTML
It has been around since the first version of JavaScript, so it's universally supported. Please note, though, that your code will not work as it currently is because you're calling go
now, and passing the result of the function as the function reference. Also, it's just history
, not location.history
. Try this instead:
setTimeout(function() { history.go(-2); }, 5000);
精彩评论