Solved

Opener/Opened window referencing

Posted on 2007-11-21
4
181 Views
Last Modified: 2010-04-21
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

0
Comment
Question by:StingRaY
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 20332865
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

0
 
LVL 15

Author Comment

by:StingRaY
ID: 20333012
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.
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
ID: 20333187
Check this try-catch method:
var wpop = null;
function popWin(){
  if (!wpop){
     wpop = window.open("", "wpop", "height=200,width=150");
  }
  try{
    var wBody = wpop.document.body.innerHTML;
  } catch(e){
    var wBody = "";
  }
  if(wBody==""){
    wpop = window.open("popwin.html", "wpop", "height=200,width=150");
  }
  wpop.focus();
}

Open in new window

0
 
LVL 15

Author Closing Comment

by:StingRaY
ID: 31410516
Zvonko

Thanks for your help. The code is working perfectly.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question