IFrame src Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:IFrame

Description

The src property sets or gets the src attribute in an iframe element, which controls the URL of the document to show in an iframe.

Set the src property with the following Values

Value Description
URL Sets the URL of the document to embed in the iframe.

Possible values:

  • An absolute URL - like src="http://www.example.com/default.htm"
  • A relative URL - like src="default.htm"

Return Value

A String, representing the URL of the document that is embedded in the iframe.

The following code shows how to change the URL of the document to embed in the iframe:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<iframe id="myFrame" src="#"></iframe>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {/*from  ww  w  . j a  va 2  s .c o  m*/
    document.getElementById("myFrame").src = "http://www.java2s.com";
}
</script>

</body>
</html>

Related Tutorials