Hi, I'm Chandra Sekar M

Sub-Categories
Technology

How to open a new window by using JavaScript with Click Event

When clicking the Button, How to open a new window by using JavaScript :

Create a Two buttons by using HTML input [or] we can use the Bootstrap buttons for simple and best [or] As per UI design.

For Example : HTML Input Buttons


<input type="button" value="Open 'newWindow'" onclick="openWin()" />
<input type="button" value="Close 'newWindow'" onclick="closeWin()" />


In Header Tag, Create a new function like openWin() for open new window and closeWin() for close that window. Both functions should be perform by click event so write a onclick attribute inside of button.

Find the full example code below,

Full Code : index.html

<!DOCTYPE html>
<html>
<head>
<script>
function openWin()
{
newWindow=window.open("","","width=200,height=100");
newWindow.document.write("<p>This is 'newWindow'</p>");
}
function closeWin()
{
newWindow.close();
}
</script>
</head>
<body>
<input type="button" value="Open 'newWindow'" onclick="openWin()" />
<input type="button" value="Close 'newWindow'" onclick="closeWin()" />
</body>
</html>

 

 

Subscribe to our Newsletter

Sign up for free and be the first to get notified about new posts.