Get window name specified when new windows are created using the Window.open() method in JavaScript

Description

The following code shows how to get window name specified when new windows are created using the Window.open() method.

Example


<html>
<head>
<script language="JavaScript">
function openWin(){<!--from w w  w  .  jav  a2  s  .c  o m-->
var myBars = 'directories=no,location=no,menubar=no,status=no';
myBars += ',titlebar=no,toolbar=no';

var myOptions = 'scrollbars=no,width=400,height=200,resizeable=no';
var myFeatures = myBars + ',' + myOptions;

var newWin = open('', 'myDoc', myFeatures);

newWin.document.writeln('This window\'s name is: ' + newWin.name + '<br>');
newWin.document.writeln('<form>');
newWin.document.writeln('<input type=BUTTON value="Close"');
newWin.document.writeln(' onClick="window.close()">');
newWin.document.writeln('</form>');
newWin.document.close();
}
</script>
</head>
<body>
<form>
<input type=BUTTON value="Open" onClick="openWin()">
</form>
</body>
</html>

Click to view the demo

The code above generates the following result.

Get window name specified when new windows are created using the Window.open() method in JavaScript