View Full Version : left AND right click

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

08-03-2008, 03: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;

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

08-04-2008, 12:16 PM
I'll give it a shot...thanks, man

08-04-2008, 11: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!");

08-04-2008, 11: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.

08-05-2008, 12:07 AM

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

08-05-2008, 03: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.

08-05-2008, 09: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...

08-06-2008, 01: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. :)

08-06-2008, 02: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