Frame/IFrame srcProperty
Frame/IFrame Object
Definition and Usage
The src property sets or returns the value of the src attribute in a frame/iframe element.
The src property specifies the URL of the document loaded into the frame/iframe.
Syntax
frameObject.src=URL
or
iframeObject.src=URL
or
iframeObject.src=URL
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the src property.
Example
Example
Change the src attribute of an iframe:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example(example.com)</title>
<script>
function changeSrc(){
document.getElementById("myframe").src="http://www.baidu.com";
}
</script>
</head>
<body>
<iframe id="myframe" src="../index.html">
<p>Your browser does not support iframes.</p>
</iframe>
<br><br>
<input type="button" onclick="changeSrc()" value="Change source link">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Example(example.com)</title>
<script>
function changeSrc(){
document.getElementById("myframe").src="http://www.baidu.com";
}
</script>
</head>
<body>
<iframe id="myframe" src="../index.html">
<p>Your browser does not support iframes.</p>
</iframe>
<br><br>
<input type="button" onclick="changeSrc()" value="Change source link">
</body>
</html>
Try it yourself »
Frame/IFrame Object Other Extensions