skip to Main Content

How can I get a button in HTML5 which when pressed plays a loop video in background and after some time redirects the page to another webpage?

2

Answers


  1. If you’re in need of a button you need to use Html to show it on screen and then use JavaScript to play the looping video and after some delay to be redirected. You’ll surely need JavaScript to do these. You should use event listeners and bind the video to be played after clicking and then add setTimeOut to wait for sometime and then use window.location.replace(…) to redirect. Here you can check for better explanation How do I redirect to another webpage?

    Login or Signup to reply.
  2. There is a huge difference between JS and Python:

    Python is server-sided and as such run on the server.
    JavaScript is client-sided and runs within the browser.

    Webservers only work with requests. For obvious security reasons, it can not control or access a browser.

    That means a server will never know if a user pressed a button because he has no control to listen to it. You need a client-sided eventListener to check for it. Then you can use a client-side script to send a post request to the server. However, for performance reasons, it should only be done if it is necessary for security reasons or UX (cross-browser and device savings).

    What you need to do:

    1. Add an eventListener to your "button" element (image?) to check for click events.
    2. The click function runs a Timer using setTimeout function.
    3. Enable loop in your video tag setup.
    4. Use a location.href method within the setTimeout to redirect when the time runs out.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search