简体   繁体   English

无法从新打开的窗口获取innerHTML

[英]Can't get innerHTML from newly opened window

I've read many questions about this issue here at StackOverflow, but nothing works. 我已经在StackOverflow上阅读了许多有关此问题的问题,但没有任何效果。 I'm trying to open a new HTML file from a HTML file and manipulate the elements. 我正在尝试从HTML文件打开一个新的HTML文件并操纵这些元素。 Here is a bit of HTML-code for newfile.html: 这是newfile.html的一些HTML代码:

<main>  
  <h1 id="myJob"></h1>
</main>

And here is a code from the js-file: 这是js文件中的代码:

newWindow = window.open("newfile.html", "Some title", "width=700, height=2500");

newWindow.onload = function () {
  newWindow.document.getElementById("myJob").innerHTML ="hello";
};

The window is opening, but nothing happens with the element. 窗口正在打开,但是元素没有任何反应。

the full newfile.html looks like this: 完整的newfile.html如下所示:

<html>
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <link rel = "stylesheet" type ="text/css"
            href = "css/theCss.css">
            <script src="myScript.js"></script> 
   </head>
        <body>
            <main>  
                <h1 id="myJob"></h1>
            </main>
        </body>
</html>

Hank 汉克

The behavior could be used for code injection. 该行为可用于代码注入。 I don't think this is supported by any serious browser. 我认为任何认真的浏览器都不支持此功能。 It would be an immense exploit. 这将是一个巨大的漏洞。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM