繁体   English   中英

window.open 从父级移除引用

[英]window.open remove reference from parent

我有一个包含报告列表的页面,单击报告后,它会将我重定向到新选项卡中的内部报告页面,其中包含:

window.open(reportIdUrl,reportId);

因此,当我回到报告列表并且我想打开相同的报告时,我将使用

window.open("",reportId);
if(redirect.location.href === "about:blank" || redirect.location.href !== '<internalreportpage>') {
        redirect = window.open(reportUrl,reportId);
        redirect.focus();
    } else {
        redirect.focus();
    }

但是,当带有内部报告页面的新选项卡中的某个人以某种方式导航到报告列表页面(在此选项卡内)然后尝试打开内部报告页面时,它将在同一选项卡中打开它,因为它是选项卡引用而不是内容引用。

当我访问 if 条件时,有人知道一些方法来删除参考吗? 就像是:

window.open("",reportId);

    if(redirect.location.href === "about:blank" || redirect.location.href !== '<internalreportpage>') {
            window.dropReference(reportId) //change_me
            redirect = window.open(reportUrl,reportId);
            redirect.focus();
        } else {
            redirect.focus();
        }

那么它会使用新的 reportId 引用创建新选项卡吗?

谢谢

例子

--reportlistpage

linkToReport1 (window.open(report1Url,1))
linkToReport2 (window.open(report2Url,2))
.
.
.
  • 您单击 linkToReport1 - 打开 2 个选项卡。 一个带有reportlistpage,一个带有internal-report/report1。

  • 您 go 返回父选项卡并单击链接到报告 1。 参考“1”打开选项卡,并将焦点放在它,并且没有打开新选项卡(这没关系)。

  • 您在 linkToReport1 上,并使用一些菜单超链接重定向到 reportlistpage(在 linkToReport1 选项卡内)。 Url 更改为 /report-list

  • 您单击链接到报告 1。 Nothing happen (this is not ok) because you are on the tab with reference to 1 (content and url changed), now you want to open a new tab with /internal-report/report1 url and store it as 1 with window references.

我想到了。 当您意识到可以设置或重置 window.name 时,这有点简单。 所以没有什么像来自父母的引用。

根据内容,您可以执行以下操作。 在您要在选项卡中跟踪的页面中,在开头(在我的情况下为 internalReport id):

var currentWindow = window.self;
currentWindow.name = reportId; //this is in case someone manually opened it without window.open(internalReportUrl, reportId)

然后在beforeunload事件上绑定window.name的重置(例如):

var resetWindowName = function() {
    var currentWindow = window.self;
    currentWindow.name = ""
}

window.addEventListener('beforeunload', resetWindowName);

因此,当您从某个地方的 internalreportpage 重定向时,名称会被清除,您可以重复调用

window.open(internalReportUrl,reportId)

这将为您打开新标签。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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