So I'm trying to put a link inside a Video element and It wont work here is the code, also How do You make a Variable as string in JS ??
var link = prompt("Enter The Website You Wanna Stream:");
document.getElementById("PLAYER").innerHTML = "<source src='" + link + "' type='video'>";
A simple way of changing the source of a video based on your code in js:
const link = prompt('Enter video Link');
const video = document.querySelector('video');
video.src = link;
full code for a test:
setTimeout(() =>{
// setting a timeout of 3s
const link = prompt('Enter video Link');
const video = document.querySelector('video');
video.src = link;
} , 3000)
<video src="https://hw5.cdn.asset.aparat.com/aparat-video/09b40b525d19c2459557117619da2c7f12978678-240p.mp4?wmsAuthSign=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbiI6IjlkNTQwYTJiMmNkZDAzMDFjODNlNjIxNjlmOWVjY2ZkIiwiZXhwIjoxNjM5MDkyNTY4LCJpc3MiOiJTYWJhIElkZWEgR1NJRyJ9.PTLqt9ltqbosdJr27icnfc_4PhUG4oVX2_IPxVXdqro" autoplay muted controls></video>
and to make a variable string you can use .toString()
const num = 123;
const str = num.toString();
bear in mind in too many cases .toString() is not needed in js. I suggest you see: js data types as well as js operators
Your code is ok. You need only wrapped in the video Tag.
function myFunction() {
const link = prompt("Enter The Website You Wanna Stream:");
if (link != null) {
document.getElementById("PLAYER").innerHTML = `<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>`;
}
}
<button onclick="myFunction()">Try it</button>
<div id="PLAYER"></div>
So I found the answer a few Minutes After I posted this which is I Have To Put The Java Script Code after The element or I have to wait For The Whole Page To Load And Then Execute The Code. If You Think You Have other Ways To Solve This Please Post a Answer