...

View Full Version : left AND right click



zoobie
08-02-2008, 10:30 PM
Hey now -
I'm a bit rusty and need my function's onclick="notice();"> to run with both left and right clicks
Thanks

binaryWeapon
08-03-2008, 02:44 AM
This may help: http://www.javascripter.net/faq/leftvsri.htm.

I went ahead and modified it to work to your situation:
<script language="JavaScript">
<!--
function mouseDown(e) {
if (parseInt(navigator.appVersion)>3) {
var clickType=1;
if (navigator.appName=="Netscape"){clickType=e.which;}
else {clickType=event.button;}
if (clickType==1){notice();}
else if (clickType!=1){notice();}
}
return true;
}
if (parseInt(navigator.appVersion)>3) {
document.onmousedown = mouseDown;
}
//-->
</script>

Works in all browsers except opera (the right click doesn't work) since by default opera blocks javascript from meddling with right-clicks.

zoobie
08-04-2008, 11:16 AM
I'll give it a shot...thanks, man

zoobie
08-04-2008, 10:30 PM
It's doing it for the whole page rather than just the div...so the user has lost all navigation
Here's notice();


function notice() {
alert ("Only members may view the videos.\nJoin instantly!");
}

binaryWeapon
08-04-2008, 10:35 PM
Right, you can change the line document.onmousedown=mouseDown; to document.getElementById("unique").onmousedown = mouseDown; (change the id to your id) or navigate the DOM with any other method.

zoobie
08-04-2008, 11:07 PM
uh...

zoobie
08-05-2008, 03:55 AM
we can all learn
<div onclick="notice();" oncontextmenu="notice();">

binaryWeapon
08-05-2008, 02:53 PM
Nice find. I could have sworn I had seen an onrightclick="" type of thing, but I couldn't find it, and this was it. And it appears to work exactly the same, too.

zoobie
08-05-2008, 08:19 PM
yep...almost perfect in it's simplicity...however, it still shows the context menu after closing the alert...wonder if there's a way to cancel that...

binaryWeapon
08-06-2008, 12:10 AM
<div onclick="notice();" oncontextmenu="notice();return false;">

However, in my opinion, blocking context menu is bad practice. Any competent user nowadays can just use the menu at the top (i.e. going to View > Page Source as opposed to Context Menu > View Source). Any competent web programmer has a bookmarklet to re-enable the context menu, or even just disables javascript.

Thats just my $0.02. :)

zoobie
08-06-2008, 01:12 AM
I was going to try inline return false but got distracted. It works fine. In my case, I'm not trying to hide anything anyway since I know better. They right click and save target as to d/l a video. I'm just alerting them to signup first.
Thanks man



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum