Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript-can';不能正确设置弹出标题_Javascript_Html - Fatal编程技术网

Javascript-can';不能正确设置弹出标题

Javascript-can';不能正确设置弹出标题,javascript,html,Javascript,Html,我想能够改变的标题和HTML内容的弹出窗口,我在页面上随意打开。 虽然更改内容(通过document.write())可以正常工作,但在我第一次更改内容后,某些原因的标题不会更改。下面是一个简短的示例代码: var targetDocument = window.open().document; targetDocument.title = "A"; targetDocument.title = "B"; targetDocument.open("text/html", "rep

我想能够改变的标题和HTML内容的弹出窗口,我在页面上随意打开。 虽然更改内容(通过
document.write()
)可以正常工作,但在我第一次更改内容后,某些原因的标题不会更改。下面是一个简短的示例代码:

  var targetDocument = window.open().document;
  targetDocument.title = "A";
  targetDocument.title = "B";
  targetDocument.open("text/html", "replace");
  targetDocument.write("<html>" + 
    "<head><title> C </title></head>" +
    "<body> Hello! </body></html>");
  targetDocument.close();
  targetDocument.title = "D";
  console.log("Title: " + targetDocument.title);
var targetDocument=window.open().document;
targetDocument.title=“A”;
targetDocument.title=“B”;
targetDocument.open(“text/html”、“replace”);
targetDocument.write(“”+
“C”+
“你好!”;
targetDocument.close();
targetDocument.title=“D”;
console.log(“标题:+targetDocument.Title”);
在该代码之后,弹出窗口显示“B”作为标题,类似地,“B”被记录到控制台(而预期为D)。我做错什么了吗


我正在使用Chrome。

这可能与加载html页面的方式有关。一旦打开,除非刷新标题,否则标题无法更改


请参见此类似问题-

它在我的一端显示D。我查了一下jsbin。原木也是D。这里的小提琴似乎很好用。。。我在Firefox上也看到了D,Chrome 42 Mac操作系统。在这些代码行之后,您的代码是否还包含其他弹出窗口的信息?如果是,那么这可能是因为javascript的引用分配。以后的作业可能会覆盖先前targetDocument的数据。如果您的“答案”以“我只是在评论…”开头,可能将其保留为评论而不是答案。更改它是因为我将其作为评论开始,但决定将其作为答案。