Javascript 代码在页面更改后不执行

Javascript code doesn't execute after the page changes

所以,我正在尝试 运行 这段代码

document.location = "https://whosebug.com/questions/ask";
document.onload = function(){document.getElementById("title").value="My question";};

但事实证明我的函数不是 运行 函数。你可以通过

观察到这一点
document.location = "https://whosebug.com/questions/ask";
document.onload = function(){document.getElementById("title").value="My question";alert('Hi');};

我的问题是,我做错了什么?为什么函数 运行?

有人问了类似的问题 here!

这里引用了被接受和投票最多的答案中最重要的部分:

No, you cannot do it the way you want. Loading a new page closes the current document and starts loading a new document. Any code in your current document will no longer be active when the new page starts to load. - Source: Answer by jfriend00