Document.write破解页面

时间:2013-05-08 14:03:10

标签: javascript ajax firefox

我已经准备了加载同步另一个视图然后用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可以处理它!)?

1 个答案:

答案 0 :(得分:1)

规范要求document.open创建新的全局。 Firefox就是这么做的。 Chrome没有;我不能代表IE。

因此,如果你依赖于旧的全球性,你的脚本将在Chrome中运行,但不适用于Firefox。

相关问题