是否通过document写入header()调用.编写一个javascript的onload函数


Will a header() call written via document.write initiate a javascript onload function?

如果我通过AJAX发送一个header()到javascript,然后使用文档写输出。写,将启动javascript的onload函数,如果文档。写写整个页面?我需要它初始化

真正的问题是document.write在初始DOM加载后是否会重新调用文档的onLoad函数。

可简单测试,答案是"否":

$(function() {
    document.write("lol");
    // ^ interestingly, `console` doesn't appear to exist after this
    alert("onload"); // only happens once
});

不会的。然而,你应该防止在调用header("Location: something.php");

后输出/执行脚本。

你可以用

die();