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

  • SEARCH
  • Home
  • 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 8926469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:58:45+00:00 2026-06-15T07:58:45+00:00

I use the following code in one of my html pages. When user clicks

  • 0

I use the following code in one of my html pages.
When user clicks "Search Engines" links it opens yahoo.com on a new page and Google on current page.

I’ve tested this and it works (opens both urls), but is there any chance that the page will complete the window.location (redirect to a different page) without completing the href command?

Is there a rule for Precedence between the two command?

**Note: I know I can solve the problem in different ways, but I’m curious about this specific situation.

<html>
<head>
    <title></title>

<script type="text/javascript">
    function clickRedirect() {
        window.location = 'http://www.google.com';
    }
</script>
<body>

<a onmousedown="clickRedirect()" href="http://www.yahoo.com" target="_blank">Search Engines</a>
</body>
</html>
  • 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-15T07:58:46+00:00Added an answer on June 15, 2026 at 7:58 am

    The mousedown event will happen first, but as you can see from the fact your code is currently working, that’s not the whole story.

    The question is: Once the mousedown has happened and you’ve set window.location, does the page get whisked away immediately (and therefore processing of the default action of the click on the a element doesn’t happen), or does that default action get completed before the page is destroyed and replaced with the new page?

    The answer is: I don’t think that’s guaranteed behavior at all (either way), and I wouldn’t rely on it cross-browser. For one thing, what if the user holds down the mouse button? Since the default action of an a element isn’t triggered until a click, which requires a mouseup.

    Instead, I’d probably hedge my bets, in two ways:

    First, I’d use click, not mousedown, for this. Users don’t expect pages to swap out when they just hold the mouse down.

    Second, I’d change your function:

    function clickRedirect() {
        setTimeout(function() {
            window.location = "http://www.google.com";
        }, 0);
    }
    

    Now you’re specifically giving the browser a chance to complete the default action of the click before you go off to another page.

    You might find more information on this buried deep in the DOM events specifications:

    • DOM2 Events
    • DOM3 Events

    …in that they might say something about what should happen when an event is in progress and the page is being destroyed. I didn’t immediately see anything.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For the following code snippets why would I use one assignment vs another? thx
I have a couple of libraries that use code similar to the following one.
I use the following code to open external pages within a div on the
I have the following snippet in one of my html pages : <div class=inputboximage>
I use following code: Create a retry policy, when error, retry after 1 second,
I just use following code to add an image to my project, var paper
I use VS2010, C# to develop Silverlight 4 app, I use following code in
I have an array of objects, and i use following code to get in
I use the following code to crop an image according to a rectangular selection
I use the following code to copy a particular directory and its contents to

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.