Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
Can put a link in a video element

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'>";
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report

0

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>

about 4 years ago · Juan Pablo Isaza Report

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!