Search code examples
javascriptprototypejs

How to hide a link from a child window


I have a mypage1.aspx, it has a link that opens a pop up, this pop up has another link that opens a second pop up and closes the first pop up. On the second pop up that was opened there is like a wizard, at the end there is an input and i have a function to close the window as follows (in Clients.js)

Clients.prototype.closeThisWindow = function() {
    window.close();
}

When the button is clicked the window perfectly. But now i have an issue from this same function i need to hide a link in the parent page but

window.parent   (parent is always null)
window.opener   (opener is always null too)

I have defined a function in the parent to hide the link, but can't call that function because opener is always null

i tried

Clients.prototype.closeThisWindow = function() {
    window.opener.hideLink();
    window.close();
}

Where hideLink is the function defined in the parent page, but opener is always null, is there any other way i could do this?. I am not good with javascript but here where I work they have designed it like this and i have to make it work from the javascript. I would appreciate any help given this scenario.


Solution

  • In the function opening the wizard do:

    var result_from_open = open(/*your paramenters*/);
    result_from_open.main_window = window.opener;
    

    And in Clients.js:

    Clients.prototype.closeThisWindow = function() {
      //window.opener.hideLink();
      window.main_window.hideLink();
      window.close();
    }