Solved

Only open a window if it doesnt already exist:

Posted on 2004-04-28
6
557 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now