Snippet. JavaScript: How to Open a PopUp Window

This JavaScript snippet shows how to open a popup window.

Open Popup Clicking on Button

<button onclick="javascript:var id=new Date().getTime();window.open('',id,'width=800, height=600, toolbar=0, location=0, directories=0, status=1, menubar=0, scrollbars=0, resizable=1, modal=yes,alwaysRaised=yes').focus(); return false;">Click to open a popup window</button>			

Test it yourself

Open Popup Clicking on Button

And this is how to open a popup window when clicking on a hyperlink.

<a href="#" onclick="javascript:var id=new Date().getTime();window.open('',id,'width=800, height=600, toolbar=0, location=0, directories=0, status=1, menubar=0, scrollbars=0, resizable=1, modal=yes,alwaysRaised=yes').focus(); return false;">Click to open a popup window</a>		

Test it yourself

Click to open a popup window

Updated on: 19 Apr 2024