Link to home
Start Free TrialLog in
Avatar of StingRaY
StingRaYFlag for Thailand

asked on

Opener/Opened window referencing

Hi all

I have 2 pages having a link to each other , a javascript code and a botton to pop window. Please see the code snippet for my js code.

When I click a button, a window is popped up.
1. If I refresh or navigate off the main page, the wpop is unaccessible.
2. If I open the link as a new window (by target=_blank or window.open or Shift+Click), the wpop in new window is unaccessible too.

I think frame can solve this problems, but there are some restrictions below.

Restrictions.
1. I do no create the main page and I cannot force the developers to use frames. If I want to use frame, I have to do something programmatically which is unable to guaratee that there is no target=_top in someone else's code.
2. The pages are not single page application. The pages must be able to refresh or navigate to other pages.

Please help.
var wpop = null;
 
function popWin()
{
  if (wpop==null || wpop=="undefined" || wpop.closed)
    wpop = window.open("popwin.html", "wpop", "height=200,width=150");
  wpop.focus();
}

Open in new window

Avatar of Zvonko
Zvonko
Flag of North Macedonia image

You did not state how you want to access the wpop window after opener window refresh.
But here the solution how you can regain the access to previous opened popup:

var wpop = null;
function popWin(){
  if (wpop==null || wpop=="undefined" || wpop.closed){
    if(!wpop){
      wpop = window.open("", "wpop", "height=200,width=150");
    }
    if(!wpop.document.body.innerHTML){
      wpop = window.open("popwin.html", "wpop", "height=200,width=150");
    }
  } 
  wpop.focus();
}

Open in new window

Avatar of StingRaY

ASKER

Zvonko,

It seems working fine, but what if I close the opener and re-open it?
I've tried in ie7. The popup window is not reload nor focused. Only flashing in title bar.

Anyway, it does not work in FF. Any advice?

PS. I want to access the wpop using popWin() function only, just pop it up or access its global functions.
ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Zvonko

Thanks for your help. The code is working perfectly.