1

&lta id="link1" href="link1"&gtlink1&lt/a&gt

what i want to realize: when i right click or left click these link, i both go to the linked pages. I have several questions:

  1. how can I get the href from jquery in firefox and IE?

  2. how can I identify the mouse event in firefox and IE, the event.which has different behaivors in firefox and in IE

Thank you very much

  • 2
    Don't keep asking [the same question over again](http://stackoverflow.com/questions/4316996/in-jquery-how-to-make-the-right-click-of-the-mouse-have-the-same-behavior-of-lef), update your previous question. – Nick Craver Dec 01 '10 at 00:37

2 Answers2

1

To get the href, which is an attribute of the a tag, you can use

var the_href = $('#link1').attr('href');

This works on all major browsers.

Camilo Díaz Repka
  • 4,805
  • 5
  • 43
  • 68
1
$('#element').mousedown(function(event) {
    switch (event.which) {
        case 1:
        alert('Left mouse button pressed');
        break;
        case 2:
        alert('Middle mouse button pressed');
        break;
        case 3:
        alert('Right mouse button pressed');
        $(this).click();
        event.preventDefault;
        break;
    }
});

(borrowed heavily from: How to distinguish between left and right mouse click with jQuery) I'm Not sure about the meaning of your #1

Adding @Camilo Díaz's answer to mine so you can have one complete answer to both your questions: for #2: var the_href = $('#link1').attr('href')

My stated answer will accomplish your goal without needing the href attribute though.

Community
  • 1
  • 1
SooDesuNe
  • 9,880
  • 10
  • 57
  • 91