开发者

Event onclick + clickable link (like facebook photo "theater")

开发者 https://www.devze.com 2023-02-22 13:10 出处:网络
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 p

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 开发者_Go百科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"


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.


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

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

cheers

0

精彩评论

暂无评论...
验证码 换一张
取 消