?
Solved

Why does onclick event not cancel href navigation?

Posted on 2008-11-06
2
Medium Priority
?
1,438 Views
Last Modified: 2012-08-13
As far as I understand the HTML code:

<html>
<head>
    <title></title>
</head>
<body>
    <a onclick="return confirm('Are you sure?');" href="http://news.bbc.co.uk">BBC</a>
</body>
</html>

should produce a HTML page with a single link that if clicked asks "Are you sure" and then if you press Cancel the link will not fire. However, it goes to the link whether I press OK or Cancel.

Why does it do this and how can I get the click to cancel?
0
Comment
Question by:BOIT
2 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 22901000
I copied exactly what you posted and it works as expected. There's nothing wrong with it. Make sure your page doesn't have a typo.
0
 

Author Comment

by:BOIT
ID: 22901140
Thank you, you are correct, the code if fine.

the problem was with the browser. I had javascript enabled - the confirm message was displaying - but the navigation occured whichever button was pressed.

I did a full reset on Internet Explorer - lost all saved passwords - the lot. The code now works correctly.

Thanks for pointing me in the right direction - I was pulling my hair out!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question