window.open在javascript中?

时间:2010-07-08 06:28:10

标签: javascript internet-explorer safari window.open

<head>
<script language="javascript" type="text/javascript">

function openMe()
{
    var win = window.open("about:blank");
    var str="";
    for(var a in win){
        str+=a+"<br/>";
    }
    document.getElementById("data").innerHTML = str;
    win.document.write("Karandeep Singh");
}
</script>
</head>

<body>
    <div>
        <input type="button" value="OK" onclick="openMe()"/>
    </div>
    <div id="data">
    </div>

上面的代码打开一个文档并写在上面。但它不适用于野生动物园。

1 个答案:

答案 0 :(得分:0)

你需要正确的HTML ......

这样做,

demo

function openMe()
{
    var win = window.open();
    var str="";
    for(var a in win){
        str+=a+"<br/>";
    }
    document.getElementById("data").innerHTML = str;
var windowHTML =
         "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>\n" +
         "<html>\n" +
         "<head></head>\n" +
         "<body>Hello World</body>\n" +
         "</html>";
      win.document.write(windowHTML);
      win.document.close();
}​