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

php - How can I go to history.back() when page loads? - Stack Overflow

programmeradmin1浏览0评论

I have a PHP page that has an error, but if I go back, it works fine. I can't redirect because the page can be accessed from two different places.

How can I make a JavaScript that loads automatically when the page loads?

Thanks, Sebastian

EDIT

that wouldn't work. is there a way to get the url of history.go(-2)?

thanks, Sebastian

I have a PHP page that has an error, but if I go back, it works fine. I can't redirect because the page can be accessed from two different places.

How can I make a JavaScript that loads automatically when the page loads?

Thanks, Sebastian

EDIT

that wouldn't work. is there a way to get the url of history.go(-2)?

thanks, Sebastian

Share Improve this question edited Oct 25, 2010 at 12:47 sebastian asked Oct 25, 2010 at 11:31 sebastiansebastian 1,5548 gold badges26 silver badges39 bronze badges 1
  • 3 I don't really understand. Wouldn't it be more sensible to fix the error in the first place? – Pekka Commented Oct 25, 2010 at 11:33
Add a ment  | 

3 Answers 3

Reset to default 2
...
<body onload="history.go(-1);">
...

The problem with using the window's onload property is that you do not want the user to wait for the current page to load. Just put this code/HTML at the top of the page right after the opening <head> tag.

<script type="text/javascript">history.go(-1);</script>

You can use the window.history object, like this:

history.back();
//or:
history.go(-1);
发布评论

评论列表(0)

  1. 暂无评论