The name
property sets or gets the name of the window.
The name
property is supported in all major browsers.
name |
Yes | Yes | Yes | Yes | Yes |
Return the name property.
var v = window.name
Set the name property.
window.name=winName
The name of the window.
The following code shows how to set the name of the window to "myWindowName".
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<!-- ww w. jav a 2 s . c o m-->
<p id="demo"></p>
<script>
function myFunction() {
window.name = "myWindowName";
var x = "This window's name is now: " + window.name;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to create a window with the open() method, and return the name of the new window.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<!--from w w w. j a v a 2s .com-->
<script>
function myFunction() {
var myWindow = window.open("", "MsgWindow", "width=200, height=100");
myWindow.document.write("<p>This window's name is: " + myWindow.name + "</p>");
}
</script>
</body>
</html>
The code above is rendered as follows: