I am trying to launching a centered browser window via a form-button using the following code…
http://www.bbc.co.uk’,’testwin’,’width=400, height=400, left=(screen.availWidth-400)/2, top=(screen.availHeight-400)/2′); return false”>
Test button
The new browser appears the correct height and width, but the left and top attributes are ignored, so the window appears top-left.
Am I being too ambitious trying to make this code in-line? Is there any other syntax I should use or should I give-up and call a function instead (I would rather not if I can avoid it)?
I am using Firefox 3.0.17 (latest), but the same effect happens in IE7.
TIA,
Alan Harris-Reid
http://www.tek-tips.com/faqs.cfm?fid=2296 explains how to do it. But I would recomend using a floating Div instead because of pop-up blockers.
Lets say you want to open a window that has a size of 200h x 150w. By taking half of the height and width (100 and 75 respectively) you can pinpoint the center of the window. Then with a little math you can center the window. Here is how it is done
To call this function in HTML use this: