Page 1 of 4 123 ... LastLast
Results 1 to 10 of 35

Thread: [DHTML] No Right Click

  1. #1
    Join Date
    Apr 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default [DHTML] No Right Click

    1) CODE TITLE: No Right Click

    2) AUTHOR NAME/NOTES: Cr0w

    3) DESCRIPTION: I keep seeing all these 100 line long no right click codes, and they always annoy me since it can be achieved in one line. So here it is.

    4) This code is so short that i saw no reason to attach it/remotely host it:

    <script type="text/javascript">
    <!--
    document.oncontextmenu=function anonymous(){ return false; }
    //-->
    </script>
    Last edited by cr0w; 04-19-2007 at 10:46 PM.

  2. #2
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    It can get smaller... -

    <script>
    <!--
    document.oncontextmenu=function() {return false}
    //-->
    </script>

    There is a slight difference...

  3. #3
    Join Date
    Apr 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    function() isn't proper javascript...you've gotta add the "anonymous"

  4. #4
    Join Date
    Apr 2007
    Location
    New York
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Doesn't work in Opera 9. And rather useless IMO, we all know this isn't going to stop anyone determined
    Last edited by cooldude42192; 04-19-2007 at 11:52 PM.

  5. #5
    Join Date
    Apr 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by cooldude42192 View Post
    And rather useless IMO, we all know this isn't going to stop anyone
    And the other 100-line-long ones already in Dynamic Drive's database are going to stop anyone?

  6. #6
    Join Date
    Apr 2007
    Location
    New York
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I didn't say they would... but the point was these scripts aren't a good "security" measure.

  7. #7
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by cr0w View Post
    function() isn't proper javascript...you've gotta add the "anonymous"
    Not at all. The function keyword is associated with two constructs: function declarations, and function expressions. With the latter, the identifier following the keyword is optional. Moreover, its scope is different: the identifier is only accessible within the body of the defined function[1].

    Any decent user agent will give users the option to override any attempts to disable the context menu, so this sort of script is guaranteed to fail for some percentage of visitors. Regardless, the context menu is an important feature and shouldn't be disabled or replaced.

    Mike


    [1] There are implementation discrepancies among some browsers, but that is how function expressions are supposed to work. Depending on other behaviour is not recommended.

  8. #8
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    The no-right click script is a joke. What if someone wants to copy for their homework? What if someone has JavaScript disabled?
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <script>
     <!--
     document.oncontextmenu=function() {return false}
     //-->
     </script>
    The type attribute is required, the HTML comment tags aren't (and will cause the whole script to be ignored in XHTML). Also, I think undefined should be interpreted in the same manner as false. Thus, the smallest possible variation in HTML 4.01 Strict would become:
    Code:
    <script type=text/javascript>document.oncontextmenu=function(){}</script>
    XHTML requires the quotes around the type attribute.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Why return 0?
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

Bookmarks

Posting Permissions

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