Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Only open a window if it doesnt already exist:

Posted on 2004-04-28
6
Medium Priority
?
590 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
[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
  • 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
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 150 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

704 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