Chrome在历史记录列表中不包含window.open("","_self")

Chrome does not include a window.open("","_self") in the history list

本文关键字:quot self open window 记录 历史 列表 包含 Chrome      更新时间:2023-09-26

下面的Javascript函数用一些新文本替换当前窗口的内容,并且还添加了一个按钮,使用户能够返回到以前的内容。这适用于FF和IE,但不适用于Chrome,显然不会将新内容页面添加到历史列表中。(使用浏览器的后退按钮时也会显示相同的行为)。

function birtaSkyr(newText){
    w = window.open("", "_self","","");
    w.document.write("<!DOCTYPE html><html><body>");
    w.document.write(newText);
    w.document.write("<p /><button onclick='javascript:window.history.back();return false;'>Close</button>");
    w.document.write("</body></html>");
    w.stop();
}

window.open()函数的四个参数中的最后一个是一个布尔变量,它应该控制是否将新页面添加到历史列表中,但它似乎被我测试过的树浏览器忽略了。

有人知道如何强制Chrome在历史列表中包含页面吗?

您应该在方法定义window.open中包含copyhistory=yes