Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8728873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:43:47+00:00 2026-06-13T08:43:47+00:00

I am attempting to write a jQuery script where whenever a link is clicked

  • 0

I am attempting to write a jQuery script where whenever a link is clicked on a certain page, a video is appended to the body, the video plays, and THEN it goes to the link’s intended target.

So far, this is what I have:

HTML

<body>
<div id="videoHolder">
<a href="http://www.google.com">Google, as an example</a>
</div>
</body>

jQuery

window.onbeforeunload=function(event) {
$("#videoHolder").html(
'<video width="600" height="600" autoplay="autoplay">' +
    '<source src="images/doors.mp4" type="video/mp4"></source>' +
     '</video>');
    setTimeout('window.location.href=' + $('a').attr(href), 5000);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:43:48+00:00Added an answer on June 13, 2026 at 8:43 am

    You need to prevent the link from redirection first, I’ve modified your code to make it work below

    <html>
      <head>
      <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
      <script type="text/javascript">
        $(function() {
        $('a').click(function(event) {
            // prevent the navigation from happening
            event.stopImmediatePropagation();
            event.preventDefault();
    
            // play the video
            $("#videoHolder").html(
            '<video width="600" height="600" autoplay="autoplay">' +
                '<source src="http://www.html5rocks.com/en/tutorials/video/basics/Chrome_ImF.mp4" type="video/mp4"></source>' +
                 '</video>');
    
            // redirect the user
            var url = $(this).attr('href');
            setTimeout(function() { window.location = url }, 5000);
    
            });
          });
        </script>     
      </head>
      <body>
        <div id="videoHolder">
          <a href="http://www.google.com">Google, as an example</a>
        </div>
      </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn jquery, so I'm attempting to write a script that'll hide
I am curretnly attempting to write a script in python that allows me to
I have been attempting to write a VBA Script that can parse out other
I'm attempting to write a very basic script using javascript. What I want to
I am attempting to write some jQuery code that will expand a paragraph when
I'm attempting to write my first jQuery plugin to query multi-dimensional arrays of complex
I am attempting a one page design using loads of jQuery. I have a
I am attempting to write a user script that makes a cross domain AJAX
I am attempting to write a JQuery to focus on the first visible, enabled
I am attempting to write a firefox addon that will analyze the displayed page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.