HTML DOM Video src Property


The HTML DOM Video src property returns/sets a string corresponding to the url of the video.

Syntax

Following is the syntax −

Returning string value

mediaObject.src

Setting src to a URLString

mediaObject.poster = URLString

Let us see an example of HTML DOM Video src property −

Example

 Live Demo

<!DOCTYPE html><html>
<head>
<title>HTML DOM Video src</title>
<style>
   * {
      padding: 2px;
      margin:5px;
   }
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style></head>
<body>
   <form>
      <fieldset>
         <legend>HTML-DOM-Video-src</legend>
         <video id="demo" width="320" controls src="http://www.tutorialspoint.com/html5/foo.mp4"
         type="video/mp4"> </video><br>
         <input type="button" onclick="getTrackDetails()" value="Get URL">
         <input type="text" id="textSelect" placeholder="Full Name...">
         <div id="divDisplay"></div>
      </fieldset>
   </form>
   <script>
      var divDisplay = document.getElementById("divDisplay");
      var textSelect = document.getElementById("textSelect");
      var demo = document.getElementById("demo");
      function getTrackDetails() {
         if(textSelect.value === 'admin')
            divDisplay.textContent = 'Video URL: '+demo.src;
         else
            divDisplay.textContent = 'Cannot Provide URL, Unauthorized User';
      }
   </script>
</body>
</html>

Output

Clicking ‘Get URL’ button after entering user name −

Clicking ‘Get URL’ button after entering “admin” as the username will allow URL access −

Updated on: 15-Feb-2021

81 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements