Code Snippet > Javascript

Open a popup window with window.open

A javascript function that opens a new window with various kind of settings.

Javascript

This function generates popup window using window.open method in javascript

function PopupCenter(pageURL, title,w,h) {
	var left = (screen.width/2)-(w/2);
	var top = (screen.height/2)-(h/2);
	var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
} 

HTML/XHTML

You can call it with the following code.

<script>
     PopupCenter('http://www.google.com', 'Google', 300, 200);
</script>

This code snippet was submitted by:

Kevin Liew is a web designer and developer and keen on contributing to the web development industry. He loves frontend development and absolutely amazed by jQuery. Feel free to say hi to me, or follow @quenesswebblog on twitter.



Show Some Love, Spread This Post!

1 comment

yaqoob Fri, 7th January 2011 Thank you :)
Reply

Leave a comment

Have something to say? Drop a comment! No HTML tags are allowed in the comment textfield.

Advertisement