ast*_*eak 3 html javascript redirect
我有一个如下页面,当用户单击 Go href 时,它将重定向到另一个页面。我想在页面完全加载后在重定向页面上进行一些 JS 操作,但这样做遇到麻烦。
我尝试通过将所有 JS 操作语句放入 setTimeout 函数来实现此目的,但似乎在加载重定向页面后这些语句不会执行。在下面的示例中,alert('in settimeout') 未执行。
你能告诉我如何实现这一目标吗?谢谢!
<!DOCTYPE html>
<html>
<body>
<a href="#" onclick="foo()">Go</a>
<script>
function foo(){
setTimeout(function (){
alert('in settimeout'); // **this will not be executed.**
//js manipulations here ...
}, 5000);
window.location.replace('http://onlineapp.ws');
}
</script>
</body>
</html>Run Code Online (Sandbox Code Playgroud)