Javascript 重定向不';t工作

Javascript 重定向不';t工作,javascript,html,Javascript,Html,我有test.html页面,加载后,我将其重定向到另一个页面: window.location.href = 'https://some.page' 但当我试图获取新页面的html源代码时: console.log("innerHTML " + window.document.documentElement.innerHTML); 我仍然得到旧test.html页面的html源代码。如何访问新加载的页面?您应该尝试: document.addEventListener("DOMContent

我有test.html页面,加载后,我将其重定向到另一个页面:

window.location.href = 'https://some.page'
但当我试图获取新页面的html源代码时:

console.log("innerHTML " + window.document.documentElement.innerHTML);
我仍然得到旧test.html页面的html源代码。如何访问新加载的页面?

您应该尝试:

document.addEventListener("DOMContentLoaded", function(event){ 
    window.open("https://some.page")
}); 
此函数首先加载文档,然后执行其中的内容。

尝试以下操作:

window.onload = function() {
 console.log("innerHTML : " + window.document.documentElement.innerHTML); 
}

window.location.href = 'https://some.page';

您能提供完整的代码吗?设置window.location是一项异步任务。您正在等待它完成吗?请尝试document.location.href='url'或window.open('url')我试图理解,当您打开外接程序时,您希望打开另一个页面,然后在上一页的js中获取innerHTML?这听起来像是有线的,如果这是您想要得到的,那就不可能了..从新页面而不是旧页面运行console.log命令。结果相同。可能问题和它是插件有关