Results 1 to 7 of 7

Thread: Text selection disable javascript & Opera Browser

  1. #1
    Join Date
    Sep 2008
    Posts
    18
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Text selection disable javascript & Opera Browser

    While the script works fine on all browsers except Opera Browser. Input fields and drop down menu becomes unclickable, how to fix it?

    My example page:

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

    Head:

    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>

    Body:


    Code:
    <script type="text/javascript">
    disableSelection(document.body) 
    </script>
    
    <script type="text/javascript">
    var somediv=document.getElementById("layer1")
    disableSelection(somediv) 
    </script>
    P.S
    You can choose install Opera as portable in installation options.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,944
    Thanks
    43
    Thanked 3,193 Times in 3,156 Posts
    Blog Entries
    12

    Default

    First of all this is sort of a silly thing to do. If the user wants the text, they can use their browser's "View Source" and copy it from there or disable javascript and select the text in the normal fashion.

    But in Opera you can try:

    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(e){if(e && e.target && e.target.tagName){if(/^(input|select)$/i.test(e.target.tagName)){return true;}}return false;}
    target.style.cursor = "default"
    }
    </script>
    The browser cache may need to be cleared and/or the page refreshed to see changes.

    No guarantee. But it might work. Otherwise, just let Opera users slide:

    Code:
    <script type="text/javascript">
    function disableSelection(target){
    if(window.opera){return;}
    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"
    }
    Last edited by jscheuer1; 12-12-2012 at 05:40 PM. Reason: code change (add && e.target.tagName) just in case
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    nizamo (12-13-2012)

  4. #3
    Join Date
    Sep 2008
    Posts
    18
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    Thank you very much jscheuer1 The script worked great. I know it but it's better than nothing. Also my site's content has became less stolen since I add this script.

  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,944
    Thanks
    43
    Thanked 3,193 Times in 3,156 Posts
    Blog Entries
    12

    Default

    You're welcome. I'm wondering though, how can you tell? How can you know your site is less stolen?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #5
    Join Date
    Sep 2008
    Posts
    18
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    I just copy a line from a page put it around quotes and see if any other site has the same content. Before this script several forums steal my content daily but now most of them give up.

  7. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,944
    Thanks
    43
    Thanked 3,193 Times in 3,156 Posts
    Blog Entries
    12

    Default

    Ah, I see. I guess this is a case where making it a little harder does make a difference. Though this is what's known as anecdotal evidence. In order to really know, you would have to do a quote from each page each day and tally up the results. At the very least you would have to use the same quote each day, but that's less scientific.

    I just noticed though that on the page you linked to in your first post that you haven't made the change yet. In Opera the drop down menu and the inputs are still disabled. But I can select the text! If I start my selection a little above and to the left of the poem I can select all or nearly all of it.

    It's because that element is the HTML element (also known as the document), and is not included in your scripts. That may also be because the page is in quirks mode, it should be the body there I think and would be covered. Either way, the way to fix that is (remove the highlighted):

    Code:
    <script type="text/javascript">
    disableSelection(document.body) 
    </script>
    So you have:

    Code:
    <script type="text/javascript">
    disableSelection(document) 
    </script>

    And now I'm wondering, when they do quote you, do they quote the entire poem, verse or whatever it is? If not, it's really a form of advertising. People will see the partial quote and search for the full text.

    But if they're generally grabbing the entire poem you are probably better off doing what you're doing. You could make a hotlink available for each page though. That's just a link to the page itself. I think most browsers will automatically make such a link if an empty href is given:

    Code:
    <a href="">Hot Link</a>
    Or you can just put the page's address there for the href. Using javascript:

    Code:
    <script type="text/javascript">document.write('<a href="' + location.href + '">Hot Link To This Page</a>');</script>
    Just put that where you want the hot link to be.

    People who want to quote you but can't, can use the hotlink in their post. If they do it will raise your site's ranking in the search engines.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #7
    Join Date
    Mar 2011
    Location
    N 11 19' 0.0012 E 142 15' 0
    Posts
    1,516
    Thanks
    41
    Thanked 89 Times in 88 Posts
    Blog Entries
    3

    Default

    Just to let you know, there is actually a way to do this in css -
    Code:
    	-webkit-user-select: none;
    	-khtml-user-select: none;
    	-moz-user-select: none;
    	-o-user-select: none;
    	user-select: none;
    However, it doesn't seem to work in Opera (and I haven't tested it in every browser)... Maybe Opera just doesn't support it...

Similar Threads

  1. Help with Disable Text Selection script
    By snoopygirl11 in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 05-26-2009, 09:03 PM
  2. Disable right click and text selection blogger?
    By smoothfreeze in forum JavaScript
    Replies: 3
    Last Post: 12-02-2008, 03:51 AM
  3. Disable Text Selection
    By sourabhmca in forum JavaScript
    Replies: 0
    Last Post: 11-28-2007, 04:52 PM
  4. Disable Text Selection script problem in Firefox
    By dandyjob in forum Dynamic Drive scripts help
    Replies: 10
    Last Post: 02-02-2007, 02:30 AM
  5. Replies: 2
    Last Post: 11-21-2006, 02:34 AM

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
  •