Solved

Only open a window if it doesnt already exist:

Posted on 2004-04-28
6
545 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
Comment Utility
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
Comment Utility
That doesn't work because the    

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

Is never reached.
0
 

Author Comment

by:MikebEdwards
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
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
Comment Utility
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
Comment Utility
Why did I get a grading B from you???
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

771 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

10 Experts available now in Live!

Get 1:1 Help Now