代码之家  ›  专栏  ›  技术社区  ›  Ciaran Archer

IE 7写入文档时出错

  •  0
  • Ciaran Archer  · 技术社区  · 17 年前

    我使用prototype JavaScript库读取文本区域的内容(通常是 标记另一个HTML页面),创建一个新窗口,然后将新窗口内容设置为相同的标记,如下所示:

    var htmlContent = $("msHTML").value;
    var win = window.open("preview.cfm", "Preview HTML", "left=20,top=20,width=500,height=500,toolbar=0,resizable=1,scrollbars=1");
    win.document.write(htmlContent); //TODO - throwing an error in IE 7 - Error Invalid Argument
    win.document.close();
    

    这在Firefox中运行得很好,但正如评论中提到的,它在IE7中给出了一个非法参数例外。

    有人能帮忙吗?

    2 回复  |  直到 14 年前
        1
  •  3
  •   scunliffe    17 年前

    的第二个参数

    window.open(url, name, features);
    

    不能 包含空格。 (影响IE的所有版本)

    //works
    window.open('page.html', 'mypage', '');
    
    //FAILS in IE
    window.open('page.html', 'my page', '');
    
        2
  •  1
  •   Konstantin Tarkus    17 年前

    从中删除URL和标题 window.open()

    var win = window.open('', '', 'left=20,top=20,' +
             'width=500,height=500,toolbar=0,resizable=1,scrollbars=1');
    
    win.document.write($("msHTML").value);