www.webdeveloper.com
Results 1 to 7 of 7

Thread: How to center pop up window

  1. #1
    Join Date
    Jan 2008
    Posts
    106

    How to center pop up window

    I have this widget in my blog, how do I center the pop up window?

    Code:
    <form style="border:1px solid #ccc;padding:3px;text-align:left; background: url(http://i50.tinypic.com/5vc86x.png);" action="http://feedburner.google.com/fb/a/mailverify" method="post" target="popupwindow" onsubmit="window.open('http://feedburner.google.com/fb/a/mailverify?uri=techglimpse', 'popupwindow', 'scrollbars=yes,width=560,height=525');return true"><p><input type="text" style="width:180px" name="email" onblur="if (this.value == '') {this.value = 'enter your email address';}" onfocus="if (this.value == 'enter your email address') {this.value = '';}" value="Enter your email address"/></p><input type="hidden" value="Techglimpse" name="uri"/><input type="hidden" name="loc" value="en_US"/><input type="submit" value="Subscribe" /></form>

  2. #2
    Try to use this:

    unction popitup(url,newH,newW)
    { var left = (screen.width-newW)/2;
    var top = (screen.height-newH)/2;
    var newW = w + 100;
    var newH = h + 100;
    myWindow = window.open(url, 'name', 'width='+newW+',height='+newH+',left='+left+',top='+top);
    myWindow.resizeTo(newW, newH);
    myWindow.moveTo(left, top);
    myWindow.focus();
    }

    hope this works...

  3. #3
    Join Date
    Jan 2008
    Posts
    106
    but how do I use the function in my code? where do i insert?

  4. #4
    Join Date
    Apr 2012
    Posts
    22
    I made a small modification of sher_amf's code

    function popitup(url,name,newH,newW)
    { var left = (screen.width-newW)/2;
    var top = (screen.height-newH)/2;
    var newW = w + 100;
    var newH = h + 100;
    myWindow = window.open(url, name, 'width='+newW+',height='+newH+',left='+left+',top='+top);
    myWindow.resizeTo(newW, newH);
    myWindow.moveTo(left, top);
    myWindow.focus();
    }


    In the code replace the onsubmit property of the form with this one:

    onsubmit="popitup('http://feedburner.google.com/fb/a/mailverify?uri=techglimpse', 'popupwindow', 525, 560)"

  5. #5
    Join Date
    Jan 2008
    Posts
    106
    This is what I did

    Code:
    function popitup(url,name,newH,newW)
    {	var left = (screen.width-newW)/2;
    var top = (screen.height-newH)/2;
    var newW = w + 100;
    var newH = h + 100;
    myWindow = window.open(url, name, 'width='+newW+',height='+newH+',left='+left+',top='+top);
    myWindow.resizeTo(newW, newH);
    myWindow.moveTo(left, top);
    myWindow.focus();
    }
    
    <form style="border:0px solid #ccc;padding:3px;text-align:left; background: url(http://i50.tinypic.com/5vc86x.png);" action="http://feedburner.google.com/fb/a/mailverify" method="post" target="popupwindow" onsubmit="popitup('http://feedburner.google.com/fb/a/mailverify?uri=techglimpse', 'popupwindow', 525, 560)"><p><input type="text" style="width:180px" name="email" onblur="if (this.value == '') {this.value = 'enter your email address';}" onfocus="if (this.value == 'enter your email address') {this.value = '';}" value="Enter your email address"/></p><input type="hidden" value="Techglimpse" name="uri"/><input type="hidden" name="loc" value="en_US"/><input type="submit" value="Subscribe" /></form>
    This is what happened
    http://i49.tinypic.com/11kf9f4.jpg

  6. #6
    Join Date
    Apr 2012
    Posts
    38
    The code u pasted, is that the actual code?
    You didn't put the function between javascript tags

    try:

    Code:
    <script type="text/javascript">
    function popitup(url,name,newH,newW)
    {	var left = (screen.width-newW)/2;
    var top = (screen.height-newH)/2;
    var newW = w + 100;
    var newH = h + 100;
    myWindow = window.open(url, name, 'width='+newW+',height='+newH+',left='+left+',top='+top);
    myWindow.resizeTo(newW, newH);
    myWindow.moveTo(left, top);
    myWindow.focus();
    }
    </script>
    <form style="border:0px solid #ccc;padding:3px;text-align:left; background: url(http://i50.tinypic.com/5vc86x.png);" action="http://feedburner.google.com/fb/a/mailverify" method="post" target="popupwindow" onsubmit="popitup('http://feedburner.google.com/fb/a/mailverify?uri=techglimpse', 'popupwindow', 525, 560)"><p><input type="text" style="width:180px" name="email" onblur="if (this.value == '') {this.value = 'enter your email address';}" onfocus="if (this.value == 'enter your email address') {this.value = '';}" value="Enter your email address"/></p><input type="hidden" value="Techglimpse" name="uri"/><input type="hidden" name="loc" value="en_US"/><input type="submit" value="Subscribe" /></form>

  7. #7
    Join Date
    Jan 2008
    Posts
    106
    It didn't worked, what it did is open to a new window...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles