Javascript href onclick open new window

Javascript code to open new window:

window.open(“http://www.google.co.in”) – opens google.co.in in new window.
window.open(“http://www.google.co.in”,”My window”) – My window is the name of the new window.

Javascript code to close the current window:

window.close() – close the current opened window.
It will ask the popup confirmation.

Javascript code to close without popup confirmation:

window.open('','_self');
window.close();
window.open("http://www.ngdeveloper.com"); // It wont allow to go back
or
window.location= "./home.jsp"; (Relative path) // allow to go back
or
window.location ="http://www.ngdeveloper.com" (Absolute path) // allow to go back

 

Program:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>window</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Rational Application Developer">
<script type="text/javascript">
function newWindow(url){
window.open(url);
}
</script>
</head>
<body>

<a href="#" onclick="newWindow('http://www.google.co.in')"/>new window</a>
</body>
</html>

 

Output:

Click to open new window

 

google on new window open

 

 

 

Thanks for reading this post……….!!!

Leave a Reply