#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    22
    Rep Power
    0

    Text selection disable script and Opera flaw


    This script works fine on all other browsers except in Opera, if you drag mouse a little above the (starting of essay) "Evliliğe Dair" then the text can be selected. How to fix this flaw?

    http://www.aymavisi.org/makale/Evlil...20Gibran).html


    Code:
    <script type="text/javascript">
    function disableSelection(target){
    if (typeof target.onselectstart!="undefined") //IE route
    	target.onselectstart=function(){return false}
    else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
    	target.style.MozUserSelect="none"
    else //All other route (ie: Opera)
    	target.onmousedown=function(){return false}
    target.style.cursor = "default"
    }
    </script>

    Code:
    </body>
    <script type="text/javascript">
    disableSelection(document.body) 
    </script>
    
    <script type="text/javascript">
    var somediv=document.getElementById("layer1")
    disableSelection(somediv) 
    </script>
  2. #2
  3. No Profile Picture
    Super Moderator
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,008
    Rep Power
    2791
    Modern versions of IE and Opera ignore selection disabling options in both Javascript and CSS.
    [PHP] | [Perl] | [Python] | [Java] != [JavaScript] | [XML] | [ANSI C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

    W3Fools - A W3Schools Intervention.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    22
    Rep Power
    0
    Not really, if I add an another empty layer just above of the "Evliliğe Dair" then text selection completely disabled for Opera but I don't want to add such layer to my 1000+ pages.
  6. #4
  7. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,126
    Rep Power
    4304
    Being able to prevent text selection can be useful for drag-and-drop scripts, but using it to prevent copy-and-pasting of text is just user-hostile. People can often just do a "Select All" and then a "Copy" anyway. And usually they could view the page's source to access the text as well.

    The web is a free (well mostly) and open medium. Get used to it.

    Comments on this post

    • Jacques1 agrees : "The web is a free (well mostly) and open medium." Kind of sad that so many "web developers" still haven't understood that.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    22
    Rep Power
    0
    Well if you spent 7 years on a site with original content then your site content becomes just a compilation of other forums and blogs you'd think different.
  10. #6
  11. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    there is no technical way to prevent people from "stealing" your content. None.

    Try to contact those websites or their hosters, try to sue them, whatever. But this JavaScript stuff will get you nowhere. Even the most retarded Internet users know how to view the page source (as Kravvitz already said). And the more intelligent ones simply disable their JavaScript or fetch the site content directly through HTTP (without any browser involved).

    So forget that "copyright script". All it does is irritate and annoy legitimate users and give the bad guys a good laugh. Actually, when a website doesn't allow me to do what I want to do, I'm out and won't come back. So this script might actually make you lose users.

    What you're trying to do is kind of a contradiction in terms: When you publish something, it's public. Anybody can view and use the data in any way they want.

    I understand your concerns, and it really is annoying to see content pop up somewhere else. But you're fighting on the wrong end.

    By the way, the script also doesn't work in Chrome. Throw it away.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    22
    Rep Power
    0
    If I add an empty layer on the text then script works with Chrome and Opera as well.

    http://www.aymavisi.org/hikaye/Anadoluda%20Bir%20Gece%20-%20Peyami%20Safa.html
  14. #8
  15. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    What are you here for when you don't care what we have to say? If you want useless help for nonsense scripts from the 90s, go to w3schools.

    I can still select the text by simply clicking outside of the layers. And if I couldn't, I'd hide the layers in my browser. That's two clicks. I don't even have to view the source.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    22
    Rep Power
    0
    Surely it's useful than what you keep saying or better than nothing. Bye.

IMN logo majestic logo threadwatch logo seochat tools logo