使链接从窗口中消失.打开弹出窗口

making link disappear from window.open pop up

本文关键字:窗口 链接 消失      更新时间:2023-09-26

我有一个打开窗口的链接,window.open("mytest.aspx");我遇到的问题是当他们关闭该弹出窗口时,我需要在父页面上隐藏该链接。所以基本上,我怎样才能从使用 window.open() 打开的弹出窗口中隐藏父页面上的链接(这是一个锚点)?

谢谢

试试这个,JavaScript Code onclick链接的事件:

function OpenPopup()
{
  document.getElementById("linkID").style.visibility='hidden';
  window.open("mytest.aspx");
}

我想你可能想看看这个类似的帖子 - 处理弹出窗口关闭的正确方法

OP 和接受的答案使用 setInterval 轮询弹出窗口。 关闭后,执行"隐藏锚点"逻辑。

希望这有帮助!

我想念理解这个问题。您可以执行以下操作:

function Popup(){
  parentWindow = this;
  window.open('mytest.aspx');  
}

在父窗口中有另一个函数:

function hideLink(){
  $("#linkID").hide()
}

然后在弹出之前调用以下函数:

parentWindow.hideLink();

对于之前的回答,我深表歉意。

您可以尝试使用 onunload 事件仅在窗口关闭时隐藏链接,"hr1"是您在打开器页面上的链接 ID:

在弹出的页面上

function CloseOpener(){ 
window.opener.document.getElementById('hr1').style.display='none'; 
} 

然后在同一个弹出的页面上:

<body onunload="CloseOpener();"> </body>

或者在同一页面上使用单独的按钮来触发关闭:

 <input id="Button1" type="button" value="button" onclick="CloseOpener();"/>

我已经对此进行了测试,它可以在我安装的浏览器上运行,但在使用此事件时仍然需要考虑一些注意事项,您可以在此处深入了解它: 卸载在 Chrome 和 safari 中不起作用

你可以尝试这样的事情:

var popup = window.open('mytest.aspx');
popup.onbeforeunload = function(){ 
   document.getElementById("theLink").style.visibility='hidden';   
}

请注意,这假设弹出页面与父级位于同一域中。