SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Code questions

  1. #1
    Non-Member spdrcr's Avatar
    Join Date
    Sep 2000
    Location
    Oklahoma City, OK
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <html>
    <head>
    <title>Centered pop-up window</title>
    
    <SCRIPT LANGUAGE="JavaScript" type="text/Javascript">
    function popUpCenteredWindow() {
    	var iMyWidth;
    	var iMyHeight;
    	//gets top and left positions based on user's resolution so hint window is centered.
    	iMyWidth = (window.screen.width/2) - (122 + 10); //half the screen width minus half the new window width (plus 5 pixel borders).
    	iMyHeight = (window.screen.height/2) - (27 + 50); //half the screen height minus half the new window height (plus title and status bars).
    	var win2 = window.open("","Window2","status,height=55,width=245,resizable=no,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",scrollbars=no");
    	win2.focus();
    }
    </SCRIPT>
    </head>
    
    <body>
    <A HREF="javascript:void(0);" onClick="popUpCenteredWindow();">open a new window centered on the screen regardless of user's resolution.
    </A>
    
    </body>
    </html>
    Alright, my question is. I'm new at the pop up windows, and I was wondering just what I needed to do to this thing so that it will open the right page. So do I need to make a new page and just have this code in it or something?

    Can someone please explain what all I need to do...
    Thanks

    SR

  2. #2
    SitePoint Wizard westmich's Avatar
    Join Date
    Mar 2000
    Location
    Muskegon, MI
    Posts
    2,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're going to want to put that script on the page you are popping from

    Don't forget to add a URL in the href link.
    Westmich
    Smart Web Solutions for Smart Clients
    http://www.mindscapecreative.com

  3. #3
    Non-Member spdrcr's Avatar
    Join Date
    Sep 2000
    Location
    Oklahoma City, OK
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok ok, kind of a obvious answer...BUT...I am also wanting to know if there is a script much like this one...that I can change the size of the box. Maybe I should just turn the scrollbar on and hope for the best.

    SR

  4. #4
    SitePoint Wizard westmich's Avatar
    Join Date
    Mar 2000
    Location
    Muskegon, MI
    Posts
    2,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change the height and width attributes second to last line. But, NOT the iMyHeight and iMyWidth; those variables set the absolute distance from the upper left corner of the screen.
    Westmich
    Smart Web Solutions for Smart Clients
    http://www.mindscapecreative.com

  5. #5
    Non-Member spdrcr's Avatar
    Join Date
    Sep 2000
    Location
    Oklahoma City, OK
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    K...thanks!!

    SR

  6. #6
    SitePoint Addict Drinky's Avatar
    Join Date
    Jan 2001
    Location
    England
    Posts
    338
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    Code:
    <html>
    <head>
      <title>Javascript popup windows</title>
      <script language="javascript">
      <!--
    
      function openPopUp(WindowURL,WindowName,X,Y){
        T = (window.screen.height/2) - (Y/2);
        L = (window.screen.width/2) - (Y/2);
        newPopUp = window.open(WindowURL,WindowName,'toolbar=no,location=no,directories=no,status=no,resizable=no,copyhistory=no,top='+ T +',left='+ L +',width=' + X +',height=' + Y)
      }
    
      //-->
      </script>
    </head>
    <body>
    
      <a href="#" onClick="openPopUp('http://www.mysite.com','myWindow',300,200)">window 1 size 300x200</a>
      <a href="#" onClick="openPopUp('http://www.mysite.com','myOtherWindow',350,250)">window 2 size 350x250</a>
    
    </body>
    </html>
    when you call the function openPopUp() you pass it a url name for the new window and the X and Y dimensions of the new window.
    <Edited by Drinky on 01-30-2001 at 11:25 PM>
    Drinky


Bookmarks

Posting Permissions

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