0

I use the same technique used by facebook javascript to display photographs.

If a user clicks on a picture (in facebook stream), the href is blocked, and part of an "onclick" event that shows the photos in "Theater. "

You can still click the right mouse button on picture and select "Open in new tab" and the picture is open in normal mode.

If I use

$("a").removeAttr ("href").css("cursor", "pointer");

within the event "onclick", the user can not click with the right sull'link and open the page in a new tab.

What to do? Ideas?


User click on a href link Example

function Message() { $("a").removeAttr ("href").css("cursor", "pointer"); //do something... }

using this trick User cannot click with right button of mouse and choose "open in a new tab"

2
  • im not sure what u want to do
    – Naftali
    Apr 5, 2011 at 21:23
  • User click on a href link <a href="page.php" onclick="javascript:Message()">Example</a> function Message() { $("a").removeAttr ("href").css("cursor", "pointer"); //do something... } using this trick User cannot click with right button of mouse and choose "open in a new tab"
    – Leonardo
    Apr 5, 2011 at 21:28

2 Answers 2

0

I believe you want to stop the url from opening on click, but still be able to right-click to open? Easy, friend, see this fiddle for the code.

Trust me, you don't want to use onclick='', nor do you want to bind this way: $("#links a").click(function(e){}); You only want to bind to one element because the more binds you have, the more resources your computer needs to run, typically slowing your code down.

-1

Try to put '#' in href, or you can add function on click which return false:

$('a').click(function(){return false;});

cheers

1
  • Don't put # in the href: in some browsers it will jump their viewport up to the top of the page. Apr 5, 2011 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.