Centering popup windows in the middle of your browser window

The script below works in both Safari and IE, but while it will pop open a window in Firefox, it doesn't size it or center it in the middle of the browser window.

I need it in the center in the bowser window due to multiple screens and some other issues.

Again, it works fine in both Safari and IE 7/8 but not FireFox.

Thanks for any help you can provide!
<!--//**************************************
// Name: Center Popup Windows
// Description:Center popup windows in the middle of your browser.
// By: Lewis E. Moten III
//
//
// Inputs:None
//
// Returns:None
//
//Assumes:None
//
//Side Effects:None
//This code is copyrighted and has limited warranties.
//Please see http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.2634/lngWId.2/qx/vb/scripts/ShowCode.htm
//for details.
//**************************************
 -->
 
function getbrowserwidth()
    {
    	if (navigator.userAgent.indexOf("MSIE") > 0)
			{
        		return(document.body.clientWidth);
        	}
        else
 
 
            {
            		return window.outerWidth;
            	}
        }
        function getbrowserheight()
 
 
            {
            	if (navigator.userAgent.indexOf("MSIE") > 0)
 
 
                	{
                		return(document.body.clientHeight);
                	} 
                else
 
 
                    {
                    		return(window.outerHeight);
                    	}
                }
                var popup = new Object()
                function CenterPopup(URL, width, height)
 
 
                    {
                    	// get center of browser window
                    	var X = getbrowserwidth() / 2
                    	var Y = getbrowserheight() / 2
                    	
                    	popup = window.open(URL, 'PopUp', 'scrollbars=yes ' + 'width=' + width + ' ' + 'height=' + height + ' ' + 'top=' + (window.screenTop + (Y - (height/2))) + ' ' + 'left=' + (window.screenLeft + (X - (width/2))) 
                    		)
                    	
                    	popup.focus()
                }

Open in new window

GSMadManAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michel PlungjanIT ExpertCommented:
VERY poor code with MANY issues and syntax errors

Please see this

<script><!--
//**************************************
// Name: Center Popup Windows
// Description:Center popup windows in the middle of your browser.
// By: Lewis E. Moten III
// Seriously Fixed: Michel Plungjan, javascripts(at)plungjan.name
//
// Inputs:None
//
// Returns:false if successfull open of window, true if not
//
//Assumes:None
//
//Side Effects:None
//This code contains so little of the original code that it can no longer be said to be copyrighted by the original author and has limited warranties.
//Please do not try to find the code here anymore: http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.2634/lngWId.2/qx/vb/scripts/ShowCode.htm
//for details.
//**************************************
//
 
function getbrowserwidth() {
  return (window.outerWidth)? window.outerWidth: document.body.clientWidth;
}
function getbrowserheight() {
return (window.outerHeight)?window.outerHeight:document.body.clientHeight;
}
function CenterPopup(URL, target, width, height) {
  // get center of browser window
  var X    = getbrowserwidth() / 2
  var Y    = getbrowserheight() / 2
  var winTop  = (window.screenTop  !=null)?window.screenTop:window.screenY;
  var winLeft = (window.screenLeft !=null)?window.screenLeft:window.screenX;
  var top  = (winTop+ (Y - (height/2)))
  var left = (winLeft + (X - (width/2)))
  var popup = window.open(URL, target, 'scrollbars=yes,width='+width+',height='+height+',top='+top+',left='+left);
  if (popup) {
    popup.focus()
    return false;
  }
  return true; // follow link, user has a popup blocker
}
// --></script>
<a href="http://www.google.com/search?q=center+popup" onClick="return CenterPopup(this.href,this.target,400,500)" target="PopUp">Click</a>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GSMadManAuthor Commented:
Thank you for your code repair! It works fine in all 3 browsers (Safari, Firefox and IE) that we support and test for.

While I didn't write the above code, comparing your changes have helped me a lot!

Thank you!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.