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 6383387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:38:34+00:00 2026-05-25T02:38:34+00:00

Here’s some sample test html: <!DOCTYPE html> <html> <body> <a href=javascript:alert(‘Not going anywhere!’);>Go nowhere

  • 0

Here’s some sample test html:

<!DOCTYPE html>
<html>
  <body>
    <a href="javascript:alert('Not going anywhere!');">Go nowhere 1</a>
    <a href="javascript:void(0);" onclick="alert('Not going anywhere!');">Go nowhere 2</a>
    <a href="http://www.google.com">Go somewhere</a>
    <script type="text/javascript">
      window.onbeforeunload = function() { return "Really leave?"; };
    </script>
  </body>
</html>

This is available as a working page here: timjeanes.com/ie9_onbeforeunload.htm

In Firefox, Chrome and Safari, I get the behaviour I want. That is, clicking either of the first two links shows an alert dialog; clicking the third link (or otherwise navigating away) shows the “Are you sure you want to leave this page?” message.

However, in IE9, the “Are you sure you want to leave this page?” message also shows when you click either of the first two links, even though no navigation is taking place – we’re just running some javascript.

Is there something I’m doing wrong? Or is there a nice workaround for IE?

One option would be to use href=”#” and put my javascript in the onclick. I’m not keen on that as it takes the user to the top of the page, and my real-life page is quite tall.

I’ve not tested in other versions of IE.

  • 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-05-25T02:38:35+00:00Added an answer on May 25, 2026 at 2:38 am

    That’s a pretty unfortunate bug. It seems you’ll have to work around it, and using the hash link method is probably the best way. To avoid taking the user to the top of the page, cancel the event using event.preventDefault() and event.returnValue = false.

    function myClickHandler(e) {
        if (e.preventDefault)
            e.preventDefault();
        e.returnValue = false;
        alert("Not going anywhere!");
    }
    

    Call it like this:

    <a href="#" onclick="myClickHandler(event)">Go nowhere 1</a>
    

    Edit: You could cancel the event for all the hash-links on your page like this:

    var links = document.links;
    for (var i = 0; i < links.length; i++) {
        var link = links[i];
        if (link.href == "#") {
            if (link.addEventListener) {
                link.addEventListener("click", cancelEvent, false);
            }
            else if (link.attachEvent) {
                link.attachEvent("onclick", cancelEvent);
            }
        }
    }
    function cancelEvent(e) {
        e = e || window.event;
        if (e.preventDefault)
            e.preventDefault();
        e.returnValue = false;
    }
    

    Or with jQuery using just one line of code:

    $("a[href='#']").click(function (e) { e.preventDefault(); });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Here's my test function (c#, visual studio 2010): [TestMethod()] public void TestGetRelevantWeeks() { List<sbyte>
Here is a snippet of my JavaScript Code that I want to DRY up:
here is the code : http://jsfiddle.net/yuliantoadi/hMr7h/ if you try to hover the 'test 2'
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here's a problem I ran into recently. I have attributes strings of the form
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here is a simplification of my database: Table: Property Fields: ID, Address Table: Quote

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.