DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Javascript Popup Window Script (save As Html File)

01.14.2007
| 16586 views |
  • submit to reddit
        // description of your code here

<html>
<head>
  <title> my javscript pages </title>

<script language="javascript">
  function mypopup()
  {
	my_Window = window.open ("page.htm","myWindow","location=1,scrollbars=1,width=500,height=300");
	my_Window.moveTo(50,50);
  }

  function popuponclick(widthVar, heightVar)
  {
	my_newWindow = window.open("","mywindow","status=1,width="+widthVar+",height="+heightVar+"");
	my_newWindow.document.write('<h1>the popup window</h1>');
  }
  
  function closepopup()
  {
	if(false == my_newWindow.closed)
	{
		my_newWindow.close();
	}
	else
	{
		alert('Window already closed!');
	}
  }
</script>

</head>

<body>

<h1 onClick='window.open("page.htm")'>onClick popup</h1>

<p onclick='window.open("page.htm","myWindow")'>onmouseover open window with name myWindow</p>

<p ondblclick='window.open("page.htm","myWindow","status=1,toolbar=1,resizable=0,width=500,height=300,scrollbars=1")'>ondblclick open window with window features argument</p>

<p onclick="javascript: mypopup()">onclick calling function mypopup</p>

<p onclick="javascript: popuponclick('10','500')">onclick calling another function popuponclick, dymanically populating text</p>
<a href="javascript: closepopup()">close popup window</a>

</body>
</html>