Audio srcProperty

Audio 对象参考手册Audio Object

Examples

Get the URL of the audio file:

var x = document.getElementById("myAudio").src;
xThe output is:
http://www.w3cschool.cc/try/demo_source/horse.ogg

Try it Yourself »

Definition and Usage

The src attribute sets or returns the current source of the audio.

The src attribute specifies the location (URL) of the audio file.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the src attribute. However, not all major browsers support the defined audio file formats.

Note:Internet Explorer 8 and earlier IE versions do not support the <audio> element.


Syntax

Return the src attribute:

audioObject.src

Set the src attribute:

audioObject.src=URL

Attribute Values

Value Description
URL

Specifies the URL of the audio source.

Possible values:

  • Absolute URL - points to another website (like src="http://example.com/movie.ogg")
  • Relative URL - points to a file within a website (like src="../data/movie.ogg.html")

Technical Details

Return value: A string representing the URL of the audio file. Returns the full URL, including the protocol part (such as http://)


Related Pages

HTML Reference Manual:HTML <audio> src Attribute.


Audio 对象参考手册Audio Object Other Extensions