Hello and welcome to our community! Is this your first visit?
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
    Thanked 2 Times in 2 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

    <!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">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script language="javascript" type="text/javascript">
    function popitup(url) {
    	if (window.focus) {newwindow.focus()}
    	return false;
    <input type=button value="Open Red River Collage" onclick="return popitup('http://www.rrc.mb.ca')" />

  2. #2
    New Coder
    Join Date
    Jan 2012
    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...)

    //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 

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

    <script type = "text/javascript">
    //code goes here
    // -->
    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 10:58 PM.

  3. #3
    New Coder
    Join Date
    Jan 2012
    Thanked 1 Time in 1 Post
    Open and center window function

    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