The Wayback Machine - https://web.archive.org/web/20250120091738/https://www.geeksforgeeks.org/html-dom-iframe-src-property/
Open In App

HTML DOM IFrame src Property

Last Updated : 20 Jul, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The HTML DOM IFrame src Property is used to set or return the value of the src attribute of the <iframe> element. This attribute is used to specify the URL of the document that is embedded in the iframe element.

Syntax: 

  • It returns the src Property. 
iframeObject.src
  • It is used to set the src Property. 
iframeObject.src = URL 

Property Values: It contains a single value URL that specifies the URL of the document that is embedded in the iframe. There are two types of URL links which are listed below:  

  • Absolute URL: It points to another webpage.
  • Relative URL: It points to other files of the same web page.

Return value: It returns a string value that represents the URL of the document that is embedded in the Iframe Element.

Example 1: This Example illustrates how to return the Iframe src Property.  

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM iframe src Property
    </title>
</head>
 
<body style="text-align:center;">
    <h1>GeeksforGeeks</h1>
    <h2>
        HTML DOM iframe src Property
    </h2>
    <iframe src=
            id="GFG" height="200"
            width="400">
    </iframe>
    <br>
    <br>
    <button onclick="Geeks()">
          Submit
      </button>
    <p id="sudo"></p>
 
    <script>
        function Geeks() {
            let x =
                document.getElementById("GFG").src;
            document.getElementById("sudo").innerHTML = x;
        }
    </script>
</body>
 
</html>


Output: 

Animation.gif

Example 2: This Example illustrates how to set the Iframe src Property. 

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM iframe src Property
    </title>
</head>
 
<body style="text-align:center;">
    <h1>GeeksforGeeks</h1>
    <h2>
        HTML DOM iframe src Property
    </h2>
    <iframe src=
            id="GFG" height="200"
            width="400">
    </iframe>
    <br>
    <br>
    <button onclick="Geeks()">
        Submit
    </button>
    <p id="sudo"></p>
 
    <script>
        function Geeks() {
            let x =
                document.getElementById("GFG").src =
                "https://ide.geeksforgeeks.org/online-cpp14-compiler";
        }
    </script>
</body>
 
</html>


Output: 

Animation

Supported Browsers: The browsers supported by HTML DOM IFrame src Property are listed below:  

  • Google Chrome 1.0 and above
  • Edge 12.0 and above
  • Firefox 
  • Internet Explorer
  • Opera
  • Safari 


Next Article
Article Tags :

Similar Reads

three90RightbarBannerImg