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

172
Views
How to open a new video every time the page is reloaded in HTML

I'm a beginner in Web development, but now have started to write cool websites. I applied a video background to my webpage, did all the stylings, and looks cool, but how can I change it every time I reload the HTML page?

<video id="vidtest" autoplay muted loop>
      <source src= "videos/vid.mp4" type="video/mp4">
    </video>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Create an array with your video paths in it, randomly select an array item, then set it as the src attribute of your video source:

var source = document.getElementById('video-source');

var videos = [
  "vid1.mp4",
  "vid2.mp4",
  "vid3.mp4"
];

var randomVideo = videos[Math.floor(Math.random() * videos.length)];

source.setAttribute('src', randomVideo);
<video id="vidtest" autoplay muted loop>
  <source id="video-source" src= "videos/vid.mp4" type="video/mp4">
</video>

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!