Advertisement
MizunoBrasil

Javascript Gera Video do Youtube pela url

Jan 28th, 2023 (edited)
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <meta charset="UTF-8">
  3. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  4. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  5.   <body>
  6.     <form>
  7.       <label>URL do vídeo do YouTube:</label>
  8.       <input type="text" size="60" id="youtubeURL" placeholder="Insira a URL do vídeo do YouTube aqui">
  9.       <button type="button" onclick="embedVideo()">Incorporar</button>
  10.     </form>
  11.     <div id="videoContainer"></div>
  12.     <script>
  13.       function embedVideo() {
  14.         var videoURL = document.getElementById('youtubeURL').value;
  15.         var youtubeID = videoURL.split('v=')[1];
  16.         var ampersandPosition = youtubeID.indexOf('&');
  17.         if(ampersandPosition != -1) {
  18.           youtubeID = youtubeID.substring(0, ampersandPosition);
  19.         }
  20.         var videoEmbed = '<iframe width="560" height="315" src="https://www.youtube.com/embed/' + youtubeID + '" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>';
  21.         document.getElementById('videoContainer').innerHTML = videoEmbed;
  22.       }
  23.     </script>
  24.   </body>
  25. </html>
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement