0

I have link that opens a window, with window.open("mytest.aspx"); the problem i am having is that when they close that pop up window I need to hide that link on the parent page. So basically, how can I hide the link (which is an anchor) on the parent page from the pop up that was opened with window.open() ?

Thank you

user1416156
  • 2,973
  • 4
  • 18
  • 14

5 Answers5

2

Try this, JavaScript Code onclick event of the link:

function OpenPopup()
{
  document.getElementById("linkID").style.visibility='hidden';
  window.open("mytest.aspx");
}
Kapil Khandelwal
  • 15,958
  • 2
  • 45
  • 52
  • I need to make it so that it closes from the pop up when they click a button to close it... this will hide the link when its opening the pop up. – user1416156 Jun 08 '12 at 19:44
  • @user1416156 So what you are saying is that you want the user to be able to continuously click the link while the popup is open? – Jeremy Jun 08 '12 at 22:12
  • Yes because while they go through a wizard, if they reach the end,only then I must hide the link – user1416156 Jun 11 '12 at 15:09
0

I miss understood the question. You can do following:

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

Have another function in parent window:

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

Then before the popup call the following function:

parentWindow.hideLink();

I apologize for previous answer.

emphaticsunshine
  • 3,725
  • 5
  • 32
  • 42
0

I think you may want to look at this similar post - The proper way to handle popup closing

The OP and accepted answer use setInterval to poll the popup. Once closed, execute your 'hide anchor' logic.

Hope this helps!

Community
  • 1
  • 1
shanabus
  • 12,989
  • 6
  • 52
  • 78
0

You can try using the onunload event to hide the link when the window is closed only, 'hr1' is your link id on the opener page :

On your popped up page

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

And then on the same popped up page:

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

Or using a separate button on the same page to trigger the closing:

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

I have tested this and it works on my installed browsers but still there are some considerations to make while using this event, you can have an insight on it here: onunload not working in Chrome and safari

Community
  • 1
  • 1
CoderRoller
  • 1,239
  • 3
  • 22
  • 39
0

You might be able to try something like this:

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

Note though that this assumes the popup page is in the same domain as the parent.

Jeremy
  • 8,902
  • 2
  • 36
  • 44