I have developed a website that uses YouTube URL. This website only uses HTML5, CSS and JavaScript. I got the URL of YouTube video as a variable, and now I want to pass it to the HTML page, where it pass to a button. When people click on that button, the video will download. How can I do that? The following is my code:
<!DOCTYPE html>
<html>
<head>
<title>Search Header</title>
</head>
<body>
<section>
<input class="downloadmp4" type="submit" value=" Download MP4 ">
</section>
<script type="text/javascript">
var dow = 'https://www.youtube.com/watch?v=' + foo;
var foo = getParameterByName('id');
//alert(foo);
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
function getParameterByName(name, url)
{
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
});
</script>
</body>
</html>
The variable is dow
. That is the complete URL of YouTube video. Now I want to pass it to the "Download MP4 button". How is it possible?
When the ID is passed to that, I also want that when people click on that button, then automatically the video will start downloading.
Two things are there: one is to pass that ID and second when ID is passed then, how it start download?