The name
attribute from iframe element
specifies the name of an iframe.
We have use the name value in the following ways.
The name
property sets or gets the value of the name attribute in an iframe element.
name |
Yes | Yes | Yes | Yes | Yes |
Return the name property.
var v = iframeObject.name
Set the name property.
iframeObject.name=name
Value | Description |
---|---|
name | The name of the iframe |
A String type value representing the name of the iframe.
The following code shows how to Change the name of an iframe.
<!DOCTYPE html>
<html>
<body>
<iframe id="myFrame" src="http://example.com" name="iframe_a"></iframe>
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<!-- ww w . ja va 2 s . com-->
<script>
function myFunction() {
document.getElementById("myFrame").name = "newIframeName";
document.getElementById("demo").innerHTML = "changed";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get the name of an iframe.
<!DOCTYPE html>
<html>
<body>
<!--from w ww . ja v a 2 s . co m-->
<iframe id="myFrame" src="http://example.com" name="iframe_a"></iframe>
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
var x = document.getElementById("myFrame").name;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: