Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: JS popup window

  1. #1
    Regular Coder
    Join Date
    Oct 2011
    Posts
    136
    Thanks
    4
    Thanked 0 Times in 0 Posts

    JS popup window

    I have this JS of a popup. Two things I don't understand. First, when I look at it in Dreamweaver It shows in the design window the text ( link to popup ) how can I get rid of that. second question is, How can I get my popup smack right in the middle of the screen istead of top left.


    Thank you


    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script language="javascript" type="text/javascript">
    
    
    function popitup(url) {
    	newwindow=window.open(url,'http://www.rrc.mb.ca','height=200,width=200,');
    	if (window.focus) {newwindow.focus()}
    	return false;
    }
    
    
    </script>
    
    
    </head>
    
    <body>
    
    <input type=button value="Open Red River Collage" onclick="return popitup('http://www.rrc.mb.ca')" />
    	
    
    </body>
    </html>

  • #2
    New Coder
    Join Date
    Jan 2012
    Posts
    20
    Thanks
    2
    Thanked 1 Time in 1 Post
    I don't use dreamweaver, but to center the window, use the following code:
    (this should be made into a function so that it is more readable, but it works just as it is...)

    Code:
    //set size variables
    var window_height = 200;
    var window_width = 200;
    var screen_height = window.screen.availHeight; 
    var screen_width = window.screen.availWidth;
    
    //set top-left corner
    var left_point = parseInt(screen_width/2) - parseInt(window_width/2); 
    var top_point = parseInt(screen_height/2) - parseInt(window_height/2);
    
    //set window to center, this would go in the popitup function
    //Note: IE does allow other_window.moveTo(), so we have to do it this way for compatibility 
    newwindow=window.open(url,'http://www.rrc.mb.ca','height='+window_height+',width='+window_width+',top='+top_point+,'left='+left_point);

    you should also use the following so that older browser's won't crash:

    Code:
    <script type = "text/javascript">
    <!--
    //code goes here
    // -->
    </script>
    the '<!--' and the '// -->' hides the code from browsers that cannot handle javascript, or if javascript is turned off.
    if these are not used, and javascript is not enabled, the rest of the page will fail to load.
    If javascript is enabled, it runs a usual.
    Last edited by Spidey1980; 01-10-2012 at 11:58 PM.

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    20
    Thanks
    2
    Thanked 1 Time in 1 Post
    http://www.codingforums.com/showthread.php?t=248554

    I have posted a fully working open and center function, I hope that it is useful!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •