javascript - "window.location.history.go(-2)" possible in major browsers? - Stack Overflow

As the title says, will this code work and will it work in major browsers?I ask because currently I hav

As the title says, will this code work and will it work in major 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

As the title says, will this code work and will it work in major 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

Share Improve this question asked Sep 28, 2010 at 9:09 user188962user188962
Add a ment  | 

4 Answers 4

Reset to default 8
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);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743798165a4508788.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>