Latest web development tutorials
 

IFrame src Property

< IFrame Object

Example

Change the URL of the document to embed in the iframe:

document.getElementById("myFrame").src = "http://www.cnn.com";
Try it Yourself »

Definition and Usage

The src property sets or returns the value of the src attribute in an iframe element.

The src attribute specifies the URL of the document to show in an iframe.


Browser Support

Property
src Yes Yes Yes Yes Yes

Syntax

Return the src property:

iframeObject.src

Set the src property:

iframeObject.src=URL

Property Values

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

Possible values:
  • An absolute URL - points to another web site (like src="http://www.example.com/default.htm")
  • A relative URL - points to a file within a web site (like src="default.htm")

Technical Details

Return Value: A String, representing the URL of the document that is embedded in the iframe. Returns the entire URL, including the protocol (like http://)

More Examples

Example

Get the URL of the document that is shown in an iframe:

var x = document.getElementById("myFrame").src;

The result of x will be:

http://www.w3ii.com/default.html
Try it Yourself »

Related Pages

HTML reference: HTML <iframe> src attribute


< IFrame Object