SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2004
    Location
    montreal
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    unselectable text

    Hey,

    I was wondering how to make the text on my page unselectable, basically, I would want for the user not to be able to copy/paste text that is on my site. I know that with text editors, users can extract text from my site quite easily, but with disableling the selection of text, at least I will deter most users.

    Thank you

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,008
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)

    unselectable text

    I don't know of any way to make it impossible using javascript. Even if you disable right-click ( - disable right-click - ), or you put the text in a containing element and use javascript to unfocus onfocus, users can disable javascript or save a copy of the page. The only "sure fire" way possible that I can think of is to change the text to images. If you have PHP with gd you can do this with imagecreatefromstring. I don't imagine too many people would want to save a bunch of image files.

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    See http://www.felgall.com/jstip35.htm for code to stop text being selectable from the page in IE5+, Netscape 6+, Mozilla, Firefox, and Opera 8+.

    Note that it doesn't stop someone stealing the text (they don't need to be able to select it to do that).
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And many people wonder why other people would choose to disable JavaScript in their browsers.

    Gotta love NoScript.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  5. #5
    SitePoint Evangelist gollux's Avatar
    Join Date
    Feb 2005
    Location
    Oregon, USA
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lessee.... Ummm... [CTRL-A], [CTRL-C], [CTRL-V] and then we have the text below. From FF.

    Ask Felgall Home page
    computer help - just ask felgall

    Search: pages images

    <== Please click on the computer image to visit our home page


    MainNavigationTopic CategoriesInteractiveRequestsContact Felgall
    Home Site Map Glossary FAQ Web Award Privacy/Disclaimer
    Back Print Find on this page
    Browsers HTML and CSS Javascript Interactive Web Mainframe PC Software Networking Comms Software Word Processing Desktop Publishing Graphics OS/2 Linux DOS/Windows NT/2000/XP Book Reviews Links
    Weblog Forums Guestmap Newsletter Tell a Friend Your Favourites
    Ask Felgall Obtain a Quote PHP Scripts Package Deals
    Link to Us Testimonials Contact Us About Us


    Disable Select and Print
    Select

    You can discourage people from selecting and copying your page content by disabling their ability to select your page content directly. To do this you need to include the following Javascript in the head section of your page.
    // disable select
    document.onselectstart=new Function('return false');
    function ds(e){return false;}
    function ra(){return true;}
    document.onmousedown=ds;
    document.onclick=ra;

    SNIP......
    Then, of course if you are doing the suggested security fix for IE with Active Script disabled, none of the above works at all...

    All this ever does is keep stupid people honest. The ones who want to rip the content usually are clever enough to do it anyway...
    Released under the Fiasco Labs Digital Damnation Copywright,
    it's yours to make whatever the 7734 you want with it.

    (c) 2005 Fiasco Labs All Wrongs Reserved

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Well it stops the actual text being selectable with the mouse which is as far as you can get with Javascript. I don't actually use that code on any other page of my site because I know how pointless it is and I don't believe in annoying visitors by restricting their access to something one way when there are at least a dozen ways to get around it. It is only used on that page so that people can see how ineffective that it actually is at blocking access to the text on the page. Still if other people want to place such codes on their site to drive all their visitors away then that is more visitors for the people who don't stupidly try to block access to web browser functions.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  7. #7
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In theory, absolutely positioning a block element to cover the text should prevent its selection. While this works in some browsers, Opera and IE < 7 fail to observe the integrity of the superimposed element if it has a transparent background.

    The implication here is that one could possibly use the superimposition strategy in conjunction with an IE-specific JavaScript approach to gain more complete coverage (though admittedly, not total), particularly in the event of JavaScript being disabled on browsers like Firefox, Konqueror, or Safari.

  8. #8
    SitePoint Member
    Join Date
    Oct 2004
    Location
    ro
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    The method i suggest for unselectable text is this one:

    Code:
    #idofelement{
    -moz-user-select: none;
    -khtml-user-select: none;
    user-select: none;
    behavior: url(ietextselect.htc);
    }
    ietextselect.htc:

    Code:
    <public:component lightweight="true">
    
        <public:attach event="ondocumentready" onevent="stopSelection()" />
    
        <script type="text/javascript">
        <!--
            function stopSelection() {
                element.onselectstart = function() { return(false); };
                element.setAttribute('unselectable', 'on', 0);
            }
        //-->
        </script>
    </public:component>


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
  •