4 out of 8 rated this helpful - Rate this topic

src attribute | src property

[This documentation is preliminary and is subject to change.]

Sets or retrieves a URL to be loaded by the object.

Syntax

HTML<element src="p" ... >
JavaScript

p = object.src

Property values

Type: String

the URL.

Remarks

Windows Internet Explorer 8 or later. In IE8 Standards mode, the value of the SRC attribute of the frame and iframe elements depends on the context of the reference to the attribute. When read as a Document Object Model (DOM) attribute, SRC returns an absolute URL. The value specified by the page author is returned when SRC is read as a content attribute, when the page is displayed in an earlier document compatibility mode, or when the page is viewed with an earlier version of the browser. For more information, see Attribute Differences in Internet Explorer 8.

Examples

This example uses the src property to change the src attribute of an iframe.



function changeFrame(){
  alert (document.all.iframe1.src);
  document.all.iframe1.src="http://www.microsoft.com/";
  alert (document.all.iframe1.src);
}

 

 

Build date: 3/8/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
error, incompatable with w3c
src doesn't actually check the current source of an object. When some user script changes the source, IE takes note of it. When you request the source IE checks what the script changed it to rather than checking the current source. If you clicked a link within the page in an iframe and therefore changed the iframes source. src would return the address of the original page instead.
error, incompatible with w3c
src doesn't actually check the current source of an object. When some user script changes the source, IE takes note of it. When you request the source IE checks what the script changed it to rather than checking the current source. If you clicked a link within the page in an iframe and therefore changed the iframes source. src would return the address of the original page instead.
How to preview a local image before uploading it, IE6; what about IE7?

<script>

ie4up=true;
function Picture3Image()
{ if(document.all.item("TFileID3") !=null){
if (ie4up){document.all.item("Picture3").src= document.all.item("TFileID3").value; }
else {document.getElementById("Picture3").src= document.getElementById("TFileID3").value;
}
}else{alert("wwwwwww");}
}

</script>

<input size="37" style=" WIDTH: 360px" id="TFileID3" name="TFileID3" type="file" onChange="javascript:Picture3Image();" >
&nbsp; </nobr> <img id="Picture3" src="Images/trans.gif" border="0" width="70px" height="91px">