Click here to Skip to main content
15,881,709 members
Articles / Web Development / HTML

Opening an image in a new closeable browser window

Rate me:
Please Sign up or sign in to vote.
2.94/5 (6 votes)
2 Sep 2006CPOL2 min read 78.6K   677   13  
This article gives an example to beginner web developers about using JavaScript functions.
<html>
<head>
	<title>Javascript example</title>
	<script>
		function OpenNewWindow(bigurl, width, height)
		{
		    var newWindow = window.open("", "pictureViewer", "location=no, directories=no, fullscreen=no, menubar=no, status=no, toolbar=no, width=" + width + ", height=" + height + ", scrollbars=no");
		    newWindow.document.writeln("<html>");
		    newWindow.document.writeln("<body style='margins: 0 0 0 0;'>");
		    newWindow.document.writeln("<a href='javascript:window.close();'>");
		    newWindow.document.writeln("<img src='" + bigurl + "' alt='Click to close' id='bigImage' border='0'/>");
		    newWindow.document.writeln("</a>");
		    newWindow.document.writeln("</body></html>");
		    newWindow.document.close();
		}
	</script>
</head>
<body>
	<a href="#" onclick="OpenNewWindow('http://www.nowan.hu/Images/nowan_logo_keretes_06.gif', 577, 410); return true;">
		<img src="http://www.nowan.hu/Images/nowan_logo_mini.gif" alt="Click..." border="0"/>
	</a>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader GSGroup
Hungary Hungary

Comments and Discussions