Returning false from click handler doesn't work in Firefox

前端 未结 3 838
星月不相逢
星月不相逢 2020-12-10 04:21

In the example below, return false does not seem to prevent the default action after the link is clicked (because the page scrolls to the top) in Firefox 3.6 or

3条回答
  •  难免孤独
    2020-12-10 05:04

    I have had some cross-browser issues with the return false method.

    I have had good luck just replacing the href of the like with the following:

    function removeLink(elementName) {
       var o = document.getElementById(elementName);
       o.href = 'javascript: (function(){})();';
       o.target = "_self";
    }
    

    I have found that this empty function in the href property has been the easiest.

    I have added the target _self part because when I develop I occasionally have these links (that I want to be hover boxes) open in a new window/tab. They need to be pointed at the current window to truly do nothing ... lol.

    Hope this helps whomever.

    Brynn

提交回复
热议问题