0

I have a bookmarklet I want people to drag to bookmarks bar. The hings is I'd like to prevent the function is fired if accidentally the bookmarklet is clicked in the web page. How can I do so?

Thanks

    <div id="bookmarklet">
      <a href="javascript:(function(){alert('mimmo');});" class="title">Bookmarklet</a>
    </div>
slwr
  • 1,105
  • 6
  • 16
  • 35

3 Answers3

1
onclick="alert('this is a bookmarklet');return false"
bluish
  • 26,356
  • 27
  • 122
  • 180
DG.
  • 3,417
  • 2
  • 23
  • 28
1

Use this:

<div id="bookmarklet">
  <a href="javascript:(function(){alert('mimmo');})()" onclick="return false" class="title">Bookmarklet</a>
</div>

Or this:

<div id="bookmarklet">
  <a href="javascript:(function(){alert('mimmo');})()" onclick="alert('Drag and drop this link onto browser toolbar to install');return false" class="title">Bookmarklet</a>
</div>

I've corrected the HREF script code since the original would declare a function without executing it.

Jay
  • 4,627
  • 1
  • 21
  • 30
0

I solved this way:

<script type="text/javascript">
    $('#bookmarklet a').mousedown(function() {
        $('#bookmarklet a').attr("href", "alert('mimmo')")
    });
    $('#bookmarklet a').mouseup(function() {
        $('#bookmarklet a').attr("href", "#")
    });
</script>
bluish
  • 26,356
  • 27
  • 122
  • 180
slwr
  • 1,105
  • 6
  • 16
  • 35