我不知道如何解决这个问题,我尝试阅读许多文章,但没有人回答。

我需要用一个已经编码的页面(在同一域内)打开一个新窗口,并添加一些内容。

问题是,如果我使用OpenWindow.write(),则该页面尚未加载,或者它覆盖所有内容,并且仅显示通过write添加的代码。

var OpenWindow = window.open('mypage.html','_blank','width=335,height=330,resizable=1');
OpenWindow.document.write(output);
output是我需要附加的代码。

我需要它至少可以在Firefox,IE和GC上运行。

提前致谢。如果我需要使用JQuery,这不是问题。

最佳答案

parent .html中:

<script type="text/javascript">
    $(document).ready(function () {
        var output = "data";
        var OpenWindow = window.open("child.html", "mywin", '');
        OpenWindow.dataFromParent = output; // dataFromParent is a variable in child.html
        OpenWindow.init();
    });
</script>

child.html中:
<script type="text/javascript">
    var dataFromParent;
    function init() {
        document.write(dataFromParent);
    }
</script>

09-25 18:28