简体   繁体   English

回到页面上载?

[英]Go back a page onload?

有没有办法让页面使用javascript或php返回页面onload?

Yes, use history.go(-1) in Javascript. 是的,在Javascript中使用history.go(-1)

For bonus points, ensure that there is actually a page to go back to before calling it, like this question suggests . 对于奖励积分,请确保在调用之前确实存在要返回的页面, 如此问题所示

PHP is server side, so no. PHP是服务器端,所以没有。 The page will get to the client and, when it reaches the client, the browser has to be instructed to go back. 页面将到达客户端,当它到达客户端时,必须指示浏览器返回。

That said you have two options. 那说你有两个选择。 Javascript or HTML Meta Tags. Javascript或HTML元标记。

Javascript mootools example would be something like this: Javascript mootools的例子是这样的:

window.addEvent('domready', function() {
   history.go(-1);
});

You can also send it in HTML Meta Tags 您也可以在HTML元标记中发送它

<meta http-equiv="refresh" content="2;url=http://example.net">

Hope it helps! 希望能帮助到你! Be aware that this behavior is, generally, confusing to the user and should be used with caution. 请注意,这种行为通常会让用户感到困惑,因此应谨慎使用。

$(function() { history.go(-1); });

Sometimes Safari in iOS ignores history.go(-1). 有时iOS中的Safari会忽略history.go(-1)。

So I prefer to use the window.history.back() method: 所以我更喜欢使用window.history.back()方法:

<body onload="window.history.back()">

You can also delay the back operation to show a temporary message in the html body: 您还可以延迟后退操作以在html正文中显示临时消息:

<body onload="setTimeout(function() { window.history.back(); }, 1000)">

另一个解决方案是:

 <body onload='history.go(-1);'> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM