Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Senior Coder
    Join Date
    Jun 2002
    Location
    ColoRockyz
    Posts
    1,646
    Thanks
    1
    Thanked 0 Times in 0 Posts

    left AND right click

    Hey now -
    I'm a bit rusty and need my function's onclick="notice();"> to run with both left and right clicks
    Thanks
    Zoobie or not Zoobie...That is the problem.
    <body onUnload="flush( ! )">

  • #2
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    This may help: http://www.javascripter.net/faq/leftvsri.htm.

    I went ahead and modified it to work to your situation:
    Code:
    <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.
    Last edited by binaryWeapon; 08-03-2008 at 02:55 AM.

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    ColoRockyz
    Posts
    1,646
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I'll give it a shot...thanks, man
    Zoobie or not Zoobie...That is the problem.
    <body onUnload="flush( ! )">

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    ColoRockyz
    Posts
    1,646
    Thanks
    1
    Thanked 0 Times in 0 Posts
    It's doing it for the whole page rather than just the div...so the user has lost all navigation
    Here's notice();
    Code:
    function notice() {
    alert ("Only members may view the videos.\nJoin instantly!");
    }
    Last edited by zoobie; 08-04-2008 at 10:39 PM.
    Zoobie or not Zoobie...That is the problem.
    <body onUnload="flush( ! )">

  • #5
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    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.

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    ColoRockyz
    Posts
    1,646
    Thanks
    1
    Thanked 0 Times in 0 Posts
    uh...
    Last edited by zoobie; 08-05-2008 at 03:54 AM.
    Zoobie or not Zoobie...That is the problem.
    <body onUnload="flush( ! )">

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    ColoRockyz
    Posts
    1,646
    Thanks
    1
    Thanked 0 Times in 0 Posts
    we can all learn
    <div onclick="notice();" oncontextmenu="notice();">
    Zoobie or not Zoobie...That is the problem.
    <body onUnload="flush( ! )">

  • #8
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    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.

  • #9
    Senior Coder
    Join Date
    Jun 2002
    Location
    ColoRockyz
    Posts
    1,646
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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...
    Zoobie or not Zoobie...That is the problem.
    <body onUnload="flush( ! )">

  • #10
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    Code:
    <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.

  • #11
    Senior Coder
    Join Date
    Jun 2002
    Location
    ColoRockyz
    Posts
    1,646
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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
    Zoobie or not Zoobie...That is the problem.
    <body onUnload="flush( ! )">


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •