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
Solved

Only open a window if it doesnt already exist:

Posted on 2004-04-28
6
567 Views
Last Modified: 2008-03-17
I have a page that on the body onload calls a funtcion to open a new window. The problem is that I only want this to happen when the window doesnt already exist. Hence the if !countentWindow. This doesnt work because the script doesnt no what contentWindow is. If i use a var contentWindow, then the if statement is always not true, and the eval is always called.

Any ideas?

function createContentWindow() {
      
      winHeight = screen.availHeight;
      maxX = screen.availWidth;
      mainWidth = maxX - 260;
            
      if (!contentWindow){
      eval ("contentWindow = window.open('about:blank', 'contentWindow', 'height=" + winHeight + ", width=" + mainWidth + ", toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes');");
            
      
      contentWindow.moveTo(260,0);

      contentWindow.resizeTo(mainWidth, winHeight)
      contentWindow.location.href="userview.asp";
      }

}



0
Comment
Question by:MikebEdwards
  • 4
  • 2
6 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 10937702
Check this:


function createContentWindow() {
   
    winHeight = screen.availHeight;
    maxX = screen.availWidth;
    mainWidth = maxX - 260;
         
    contentWindow = window.open('', 'contentWindow', 'height='+winHeight+',width='+mainWidth+',toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes');
    if(!contentWindow.document.body){
      contentWindow.location.href="userview.htm";
      contentWindow.resizeTo(mainWidth, winHeight)
      contentWindow.moveTo(260,0);
    }

}


0
 

Author Comment

by:MikebEdwards
ID: 10937946
That doesn't work because the    

contentWindow.location.href="userview.htm";

Is never reached.
0
 

Author Comment

by:MikebEdwards
ID: 10938015
This does seem to work though:

function createContentWindow() {
   
    winHeight = screen.availHeight;
    maxX = screen.availWidth;
    mainWidth = maxX - 260;
         
    contentWindow = window.open('', 'contentWindow', 'height='+winHeight+',width='+mainWidth+',toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes');
    if(contentWindow.location.href!='about:blank'){}
      else {
      contentWindow.location.href="userview.asp";
      contentWindow.resizeTo(mainWidth, winHeight)
      contentWindow.moveTo(260,0);
    }

}
0
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.

 
LVL 63

Expert Comment

by:Zvonko
ID: 10938120
Does this work for you:

function createContentWindow() {
   
    winHeight = screen.availHeight;
    maxX = screen.availWidth;
    mainWidth = maxX - 260;
         
    contentWindow = window.open('', 'contentWindow', 'height='+winHeight+',width='+mainWidth+',toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes');
    if(!contentWindow.myWindow){
      contentWindow.location.href="userview.htm";
      contentWindow.resizeTo(mainWidth, winHeight)
      contentWindow.moveTo(260,0);
      contentWindow.myWindow=true;
    }
}

0
 
LVL 63

Accepted Solution

by:
Zvonko earned 50 total points
ID: 10938162
Yea! That was the solution :-)

function createContentWindow() {
   
    winHeight = screen.availHeight;
    maxX = screen.availWidth;
    mainWidth = maxX - 260;
         
    contentWindow = window.open('', 'contentWindow', 'height='+winHeight+',width='+mainWidth+',toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes');
    if(contentWindow.location.href=="about:blank"){
      contentWindow.location.href="userview.htm";
      contentWindow.resizeTo(mainWidth, winHeight)
      contentWindow.moveTo(260,0);
    }
}


0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10939062
Why did I get a grading B from you???
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

839 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