Return the URL of an embedded file:
var x = document.getElementById("myEmbed").src;
Click the button to return the value of the src attribute of the embed element.
<!DOCTYPE html> <html> <body> <embed id="myEmbed" src="video.mp4"> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//w w w . ja va 2 s.c o m var x = document.getElementById("myEmbed").src; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The src
property sets or gets the value of the src attribute in an embed element.
The src
attribute sets the address (URL) of the external file to embed.
The src
property accepts and returns a String value.
Property Values
Value | Description |
---|---|
URL | Set URL of the external file to embed. |
The src property returns a String representing the URL of the embedded file.