为什么不在窗口后编写代码?公开招股被执行

Why doesn't code after a window.open call get executed?

本文关键字:执行 代码 窗口 为什么不      更新时间:2023-09-26

我有一些非常简单的javascript代码,看起来像这样:

var newWindow = window.open("","");
if (newWindow != null)
{
   newWindow.document.write("<HTML><HEAD><TITLE>hi</TITLE></HEAD>");
   newWindow.document.close();
}
document.getElementById('status1').innerHTML = "opened a new window";

但是由于某些原因document.getElementById…部分永远不会被调用。这是意料之中的,还是我做错了什么?(是的,定义了status1)

正如Guffa所说,查找错误消息。newWindow.document可能为空或未定义,因为打开窗口的时间可能比执行newWindow != null的时间长。