I have a page as below, when user clicks the Go href, it will redirect to another page. I want to do some JS manipulations on the redirected page after the page is fully loaded, but have trouble in doing this.
I tried to achieve this by putting all JS manipulations statements to a setTimeout function, but it seems the statements will not be executed after the redirected page is loaded. In below example, alert('in settimeout') was not executed.
Can you tell me how to achieve this? Thanks!
<!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>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…