HTML DOM Source src attribute
Examples
Returns the URL of the media file:
var x = document.getElementById("mySource").src;
x The output is:
http://www.w3cschool.cc/jsref/horse.mp3
try it"
Definition and Usage
src property sets or returns the <source> element in the value of the src attribute.
Src attribute specifies the URL you want to play media files.
Note: <source> element is new in HTML5.
Note: Internet Explorer version 8 and earlier, only returns the file name (for example horse.mp3), instead of returning URL (for example http://www.w3cschool.cc/jsref/horse.mp3).
Browser Support
All major browsers support the src attribute.
grammar
Back src attribute:
sourceObject .src
Setting the src attribute:
sourceObject .src=URL
Property Value
值 | 描述 |
---|---|
URL | 规定媒体文件的 URL。 可能的值:
|
technical details
return value: | String representing the URL of the media file. Returns the complete URL, including the protocol (such as http: //). |
---|
related articles
HTML Reference Manual: HTML <Source> the src attribute