Latest web development tutorials

HTML DOM Audio src attribute

Audio Object Reference Audio Object

Examples

Get URL of the audio file:

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

try it"

Definition and Usage

src property sets or returns the current audio source.

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


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the src attribute. But not all major browsers support the definition of audio file formats.

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


grammar

Back src attribute:

audioObject .src

Setting the src attribute:

audioObject .src= URL

Property Value

描述
URL

规定音频来源的 URL。

可能的值:

  • 绝对 URL - 指向另一个网站(比如 src="http://example.com/movie.ogg")
  • 相对 URL - 指向网站内的某个文件(比如 src="/data/movie.ogg")

technical details

return value: String representing the URL of the audio file. Back entity URL, including the protocol (such as http: //)


Related Pages

HTML Reference Manual: HTML <Audio> the src attribute.


Audio Object Reference Audio Object