【发布时间】:2015-10-20 02:37:28
【问题描述】:
我有一个如下页面,当用户点击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>
【问题讨论】:
标签: javascript html redirect