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 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    New popup window - how to make it in the center always?

    Hello.

    I need to carry out javascript which develope new window(open.window) This window must appear in the middle of bigger window along with size changing of bigger window small must be all the time in the middle of the bigger one
    Please someone help me ;(

    This is what i have now:

    <HTML>
    <HEAD>
    <SCRIPT>
    <!--
    var okno;
    // Opens new window
    function otworz()
    {
    okno=window.open('', 'Wiadomosci', 'scrollbars,height=300,width=300');

    }

    </SCRIPT>
    </HEAD>
    <BODY onLoad="otworz()" onunLoad="zamknij()">
    </BODY>
    </HTML>


    Please help me!

    Regards Peter
    Last edited by 2blaze; 06-12-2007 at 01:01 PM. Reason: advice from another user - my bad

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,907
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Is this what you mean?

    <HTML>
    <HEAD>

    <script type="text/javascript">
    function openWin(url,wid,hgt)
    {
    sh = (screen.height - hgt) / 2;
    sw = (screen.width - wid) / 2;
    var newwin = window.open(url,'win','width='+wid+',height='+hgt+',top='+sh+',left='+sw+'');
    if(newwin) newwin.focus();
    return false;
    }
    </script>
    </HEAD>

    <BODY>
    <a href="http://www.yoururl.com" onclick="return openWin(this.href,400,300)">Open New Window in Centre</a>

    </BODY>
    </HTML>


    Please see the Posting Guidelines re silly thread titles. This thread title is not very helpful to anyone searching for this topic in the future.

  • #3
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeah, sorry


    Hm yes this small window opens in the centre but if you try to resize the bigger one, smaller remains in the same position. ;(

    I am trying to make something with window.onresize event...but i cant ;(

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    What will happen if the user resizes the bigger window to make it smaller than that popup window?

  • #5
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes good question

    It will be good when there will be min value of size(big window) ofcourse bigger than the smaller one.

  • #6
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    http://popups.biz/

    here is example

  • #7
    Regular Coder
    Join Date
    Jun 2007
    Posts
    805
    Thanks
    123
    Thanked 23 Times in 23 Posts

  • #8
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ...this generator will not help...

  • #9
    Regular Coder
    Join Date
    Jun 2007
    Posts
    805
    Thanks
    123
    Thanked 23 Times in 23 Posts
    Why? It has a checkbox which says: "Should we center the window on screen?"

    I guess that was what u were looking for?

    EDIT: Or wait! Now I see it...sorry lol.

  • #10
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    On the popup pages add this in between the head tags.
    Code:
    <style type="text/css">
    html, body {
    margin:0;
    padding:0;
    height:100%;
    }
    </style>
    <script type="text/javascript">
    function f_clientWidth() 
    {
    	return f_filterResults 
    	(
    		window.innerWidth ? window.innerWidth : 0,
    		document.documentElement ? document.documentElement.clientWidth : 0,
    		document.body ? document.body.clientWidth : 0
    	);
    }
    function f_clientHeight()
    {
    	return f_filterResults 
    	(
    		window.innerHeight ? window.innerHeight : 0,
    		document.documentElement ? document.documentElement.clientHeight : 0,
    		document.body ? document.body.clientHeight : 0
    	);
    }
    function f_filterResults(n_win, n_docel, n_body)
    {
    	var n_result = n_win ? n_win : 0;
    	if (n_docel && (!n_result || (n_result > n_docel)))
    		n_result = n_docel;
    	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
    }
    function moveIt()
    {
    	sw = parseInt((screen.width - f_clientWidth()) / 2);
    	sh = parseInt((screen.height - f_clientHeight()) / 2);
    	window.moveTo(sw,sh);
    }
    window.onresize = function()
    {
    	setTimeout("moveIt()",500);
    }
    </script>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #11
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK i made it

    <html>
    <head>
    <script type="text/javascript">
    <!-- <![CDATA[

    rozmiarx = 300;
    rozmiary = 200;
    okno = open("about:blank","nazwa","width="+rozmiarx+",height="+rozmiary);

    function wykonaj() {
    if (!window.screenLeft) {
    pozx = window.screenX;
    pozy = window.screenY;
    } else {
    pozx = window.screenLeft;
    pozy = window.screenTop;
    }
    var wysokosc = szerokosc = 0;
    if (typeof(window.innerWidth)=='number') {
    szerokosc = window.innerWidth;
    wysokosc = window.innerHeight;
    } else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
    szerokosc = document.documentElement.clientWidth;
    wysokosc = document.documentElement.clientHeight;
    } else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
    szerokosc = document.body.clientWidth;
    wysokosc = document.body.clientHeight;
    }
    pozycjax = pozx+szerokosc/2-rozmiarx/2;
    pozycjay = pozy+wysokosc/2-rozmiary/2;
    okno.focus();
    okno.moveTo(pozycjax,pozycjay);
    okno.focus();
    setTimeout("wykonaj()", 300)
    }
    //window.onresize=wykonaj;
    //window.onclick=wykonaj;
    setTimeout("wykonaj()", 300)
    // ]]> -->
    </script>
    <head>
    <body>
    </body>
    <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
    •