Popup windows in Javascript

In this tutorial we will learn how to create popup windows in javascript. Before creating popup windows let's understand what are popup windows.

Popup windows are additional windows infect additional web browser windows opened from a webpage. These windows are created by using javascript as a client side programming language.

Popup windows are widely used for the advertisement, to exchange the banners, polling, requesting signup for news letter etc.

Now let's look over the code to develop popup windows in javascript.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>popup windows in javascript</title>
<script language="javascript" type="text/javascript">
function openPopupWindow()
{
window.open("http://www.google.com",'Google','height=200, width=500,top=100,resizable=no,scrollbars=no,toolbar=no,status=no,menubar=no');

}
</script>
</head>
<body>
<form>
<input type="button" value="Click to open Popup Windows in Javascript" onclick="openPopupWindow();">
</form>
</body>
</html>

First of all we made a custom function and give it a name openPopupWindow(), in this function we simply call the built-in function windows.open() and give some parameters to window.open() function which are used for specifications for popup window that is going to be open. In this example the first parameter is webpage/website name, second parameter is the name given to the popup window, third parameter is the height, fourth is the width, fifth parameter handles the top margin to display popup window in the current window, sixth one is self explanatory, seventh parameter means there will be no scrollbar in the popup windows that is going to be open, eighth parameter means there will be no status bar, and last parameter means there will be no menubar in the popup window.

Happy Coding, Keep Coding…!

0 comments: