A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: centering a pop-up window

  1. #1
    Junior Member
    Join Date
    Aug 2001
    Posts
    8

    Red face

    I have an html page that resizes to whatever the users screen rez is. I then have a "launch site button" that launches the flash movie in a constrained window..... all works, but the window always pops up in the upper left corner of the screen. Is there a way to always have it centered on the screen, based on the current size of the background window (it changes based on the screen rez) all help would be greatly appreciated..... -Fred

  2. #2
    Welcome to Flashkit, generalfred!

    There's probably at least one thread on this subject, but this is what I use:
    In your intial HTML page:
    <script language="JavaScript">
    <!--

    function openNewWindow(URL,winName,features){
    var xPos = (screen.width-700)/2;
    var yPos = (screen.height-400)/2;
    newWin=window.open(URL,winName,features);
    newWin.moveTo(xPos,yPos);
    newWin.focus();
    }

    -->
    </script>
    In this case, a Flash button to launch the window:
    on (release) {
    getURL ("javascriptpenNewWindow ('yourfile.html','wp','width=700,height=400,scroll bars=no')");
    }
    Note: The window dimensions are defined in the getURL command.

    Enjoy!

  3. #3
    Junior Member
    Join Date
    Aug 2001
    Posts
    8
    Thanks!

  4. #4
    Junior Member
    Join Date
    Aug 2001
    Posts
    8

    HELP!!! Over here!!!

    for the life of me, I can't get this to work! I've searched EVERYWHERE to find a solution.... no avail! I just need the main HTML page to maximise (win/mac), and after clicking an html link, pop open window in the center of the screen... please help, before I'm bald from pulling out my hair!!! : )

  5. #5
    Member
    Join Date
    Sep 2000
    Posts
    60
    Hi there,

    I'm also trying to get a pop-up window to centre on screen. I am a complete novice and cannot hand code html so could you please walk me through step by step on where exactly to put this script, as the code appears on my page when I type it in. Please help. I'm already bald!


  6. #6
    Senior Member
    Join Date
    Apr 2001
    Posts
    296
    Try this:
    Code:
    <html>
    <head>
    <script language="javascript">
    <!--
    //
    //change popWidth and popHeight as appropriate
    //
    var initialContent = "whatever.html";
    var popWidth = 400;
    var popHeight = 300;
    //
    //no need to change any script below here
    //
    var popX = (screen.availWidth/2)-(popWidth/2);
    var popY = (screen.availHeight/2)-(popHeight/2);
    var popped = null;
    var winAtts = null;
    var oldBrowser = false;
    //
    function popOne(){
    	if(!window.resizeBy){	
    		oldBrowser = true;
    	}
    	winAtts = getWinAtts();
    	popped = window.open(initialContent,'noname',winAtts);
    }
    //
    function getWinAtts(){
    	winAtts = "width=" + popWidth + ",height=" + popHeight;
    	//used for IE
    	winAtts += ",left=" + popX + ",top=" + popY;
    	//used for netscape
    	winAtts += ",screenX=" + popX + ",screenY=" + popY;
    	if (!document.all) {
    		winAtts += ",resizable=1"
    	}
    	return winAtts;	
    }
    //
    function closePopped(){
    	if(popped != null){
    		if(!popped.closed){
    			popped.close();
    		}
    	}
    }
    //
    popOne();
    //-->
    </script>
    <body>
    </body>
    </html>

  7. #7
    Senior Member
    Join Date
    Apr 2001
    Posts
    296
    This is taken from my generic window resizer at http://www.shavencat.com/experiments/windowResizer.html

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center