繁体   English   中英

Document.write中断页面

[英]Document.write brokes page

我已经准备好加载aync另一个视图的视图,然后用document.write替换当前视图(是的,我想替换整个页面!):

$.ajax({
type: "GET",
url: myUrl,
data: null,
async: true,        
success: function (result) {

    document.close();
    document.open();
    document.write(result);
    document.close();
},
error: function (req, status, error) {
    $("#loading-div").html("error");
}
});

内容是具有自己的脚本和CSS样式的完整视图。 使用IE或Chrome时,一切正常。 当我在firefox中加载页面时,通过document.write加载的页面似乎无法正常工作-尤其是脚本(有些作品,有些则没有)。

由于脚本未评估,我无法使用innerHTML。

为什么它仅在Firefox中不能正常工作(即使IE也可以处理!)?

该规范要求document.open创建一个新的全局变量。 Firefox做到了。 Chrome不会; 我不能代表IE。

因此,如果您要依靠旧的全球化技术,那么您的脚本可以在Chrome浏览器中运行,但不能在Firefox中运行。

暂无
暂无

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

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