【问题标题】:window.opener.location.href history not working on firefoxwindow.opener.location.href 历史在 Firefox 上不起作用
【发布时间】:2021-01-29 10:01:15
【问题描述】:

我正在使用 window.open 打开一个窗口,在该窗口中单击链接时会出现某些链接,它将原始页面重定向到单击的链接并关闭新窗口。

$('a').on('click',function(e){
  e.preventDefault();
  var get_href=$(this).attr('href');

  window.opener.location.href=get_href;
  window.close();
});

现在,当我单击 chrome 中的后退按钮时,重定向会将我们带到预订页面,它会将其带回帐户页面,但是当我在 firefox 上尝试时,它会将页面重定向到登录页面,而不是它应该重定向到帐户页面。如果我们可以重新加载页面也可以。

我试过了

window.onbeforeunload = function(){window.location.reload();}

这在 php 头文件中

// any valid date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified right now
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1 
header("Cache-Control: private, no-store, max-age=0, no-cache, must-revalidate, post-          check=0, pre-check=0");
// HTTP/1.0
header("Pragma: no-cache");

但是没有一个在工作下面的代码正在工作它正在引发警报但没有重新加载

window.addEventListener("beforeunload", function (e) {
  var confirmationMessage = "\o/";

  (e || window.event).returnValue = confirmationMessage; //Gecko + IE
  return confirmationMessage;                            //Webkit, Safari, Chrome
});

【问题讨论】:

    标签: javascript firefox browser-history back


    【解决方案1】:

    window.onbeforeunload = function(){window.location.reload();} 永远不会工作。那是拒绝服务攻击

    假设页面来自同一来源,您可以试试这个

    1. 在父母中:

    window.name="parentWindow"

    1. 在儿童中

    <a href="page.html" target="parentWindow">Open page in parent</a>

    【讨论】:

    • 我试过了,但它不起作用请注意我使用的是 iframe,所以浏览器中的 url 保持不变,只是 iframe url 发生变化
    • 您在哪里使用 iframe? iFrame 中的页面具有顶部或父级,而不是打开器如果链接在 iFrame 中,则命名的目标窗口应该仍然有效
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-06
    • 2011-03-10
    • 2011-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-30
    相关资源
    最近更新 更多