简体   繁体   English

<body>和onload setTimeout与history.go

[英]<body> and onload setTimeout with history.go

I have the following page that has a button called "update". 我在下面的页面上有一个名为“更新”的按钮。 updatepage 更新页

If the user click on the update button, i will redirect like this 如果用户点击更新按钮,我将重定向像这样

What i want is, if the user click on the button update, it show the redirect pages for 2-4seconds, and it will back to the "history.go" 我想要的是,如果用户单击按钮更新,它将显示2-4秒的重定向页面,并且它将返回到“ history.go”

Here is I tried so far, I put onload on body (in redirect page form) 到目前为止,这是我尝试过的方法,我将onload放在主体上(以重定向页面的形式)

<body id="main_body" onload="setTimeout(history.go(-2), 4000);">

The problem is, the page is not wait for 4 seconds, after I click on the update button, it will instantly redirect to the (history.go(-2)). 问题是,页面没有等待4秒钟,单击更新按钮后,它将立即重定向到(history.go(-2))。 It should wait 4 seconds (in redirect page form) then after 4 seconds, it will go to history.go(-2). 它应该等待4秒钟(以重定向页面的形式),然后在4秒钟后转到history.go(-2)。 How to overcome this ? 如何克服呢? Please help 请帮忙

使用setTimeout函数

setTimeout(function(){history.go(-2);}, 4000);

或使用箭头函数语法(更短)

<body id="main_body" onload="setTimeout(()=>{history.go(-2)}, 4000);">

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

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