简体   繁体   中英

Document.write brokes page

I've prepared view that loads aync another view and then replace current with document.write (yes, I want to replace whole page!):

$.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");
}
});

The content is full view with own scripts and css styles. When using IE or Chrome everything works fine. When I load page within firefox, loaded page via document.write doesn't seems to be working properly - especially scripts (some works, some don't).

I can't use innerHTML due to scripts that are not evaluated.

Why it doesn't work properly only in Firefox (even IE can handle it!)?

The specification requires document.open to create a new global. Firefox does that. Chrome does not; I can't speak for IE.

So if you're depending on the old global sticking around, your script will work in Chrome but not Firefox.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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