Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firefox javascript return false in href redirects the browser and displays false

following is my code working well in chrome.

<body>

<a href="javascript: sam.save();">hehe</a>

<script>

var sam = {
    save : function()
    {
        alert("here")
            return false;       
    }
}
</script>

when in run in firefox the page redirects and false is displayed on the screen with the adress bar content like in the picture

enter image description here

firefox version is 9.0.1

suggestions and circumvents please...

like image 416
Jayapal Chandran Avatar asked Jun 08 '12 12:06

Jayapal Chandran


People also ask

Why do we return false in Javascript?

Web Developers use 'return false' in different ways. During form submission, if a particular entry is unfilled, return false is used to prevent the submission of the form.

How do I enable redirects in Firefox?

Chosen solution You can open the about:config page via the location/address bar. You can click the button to "Accept the Risk and Continue".


1 Answers

For some reason return false doesn't work in FF inside href="javascript:", but void(0) does.

<a href="javascript: sam.save();void(0);">hehe</a>
like image 152
boateng Avatar answered Oct 30 '22 07:10

boateng