I already put a code to not allow right clicking, now I need to prevent highlighting of text; but I know nothing of html. Thanks in advance
Frankly, you could've easily found what you're looking for on Google Here's something from Dynamic Drive: Add this script to the HEAD section of your page: <script type="text/javascript"> /*********************************************** * Disable Text Selection script- © Dynamic Drive DHTML code library (www.dynamicdrive.com) * This notice MUST stay intact for legal use * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code ***********************************************/ 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" } //Sample usages //disableSelection(document.body) //Disable text selection on entire body //disableSelection(document.getElementById("mydiv")) //Disable text selection on element with id="mydiv" </script> Code (markup): With the script installed, just call the function disableSelection(target) at the very end of the document with a reference to the element you wish to disable text within. A few examples: Disable text selection on ENTIRE BODY of page: <script type="text/javascript"> disableSelection(document.body) //disable text selection on entire body of page </script> Code (markup): Disable text selection with DIV with id="mydiv" << you'll probably have different names for your DIVs: <script type="text/javascript"> var somediv=document.getElementById("mydiv") disableSelection(somediv) //disable text selection within DIV with id="mydiv" </script> Code (markup): Disable text selection within all tables on the page: <script type="text/javascript"> var alltables=document.getElementsByTagName("table") for (var i=0; i<alltables.length; i++) disableSelection(alltables[i]) //disable text selection within all tables on the page </script> Code (markup):
Which won't work in Opera, and most likely not Firefox or Safari. Best scrap the idea altogether. Nothing says "Please leave this page" when I can't highlight what I read.
I kind of agree with this. That script from DynamicDrive does work on FireFox, but I don't know about all the other browsers. It's easy to disable it though; simply disable Javascript on your browser. If you're (thread starter) afraid of people stealing from your site, the best and only solution is not to publish it online (at all). Disabling right click and highlighting won't stop people from stealing from your site. G'luck
Actually, I have tested that script and I know for sure that it works in Firefox. Because of the fact that both Firefox and Safari follow very similar web standards, that probably means that it would work in Safari also.
True!!!! Very... however if it is protected content or certain content... I'd go with that.... But highlighting isnt this guys problem... REMEMBER::: text or any html for that matter is read by the client computer... So hiding it is near impossible 100% if it is viewable... Tips::: Disable the ctrl key, disable the menu - edit ->copy/paste options, and anything you want to protect, create dynamically or dynamicly load it... ie... using php you can hide .js file content well... probly not all you can do but just some pointers. There are a lot of reasons to disable highlighting.... For me it is temporary. When someone on mouses down to move an object ; for instace a image; (saying your dragging funcs are made) if the mouse moves too quickly it rolls off of the image and highlights the page for a second. even itself at times... so the obvious course of action is to dissable it on mouse out while mouse down then enable it on mouse up...
IF YOU DONT WANT IT TO BE STOLEN, DONT PUT IT ONLINE. The nature of the internet states that before they can view it on their machine, it's sent a copy of the text/files to their computer already. Theres already a file on their computer that contains everything they see even before it shows up to their eyes. Preventing highlighting is a dick move, and it will drive people away from your site faster than anything. Personally, I highlight sections as I go along like one might trace their finger along a line as they read it. It's how I keep track of where I am. Prevent me from doing that an I won't read it, I'll simply leave your page and never go back. As for right clicking, as I browse online I often have 4 or 5 tabs open, I open links in new tabs that I am interested in reading by rightclicking. If you disable that it's a slap in the face. If I wanted your image that you want to keep, I don't need to right click to get it if I want it, I can take a screenshot, I can save the entire page, and fish the image out of the folder, I can hit control-I in firefox and save the images on the page individually or I can go into my browser cache and fish the image out of where it's already on my hard drive. If I really want it, I have PLENTY of way to get it, but if you disable my right click, that's a slap in the face, spitting in my eye and then telling me you don't want me to see your website. So I won't. End of story. It sounds to me like you have control issues over your content (or maybe it's not even your content). This is the internet, the nature of it is open, and if you don't like that, go print a brochure and stay off the internet until you're ready to be mature and do things the way they've been done for 20 years. Good luck to you, and I really hope you smarten up before you alienate every single person you are aiming your site towards.
Not to mention people like me will go out there way to obtain your "protected" content just because you've tried to protect it
Did it ever occur to anyone that you should disable highlighting if you're writing a touchscreen/kiosk application? FYI that's what I'm doing. I came here to find the answer to this and found another site instead. I came back to blow your minds in case you never thought of a valid reason to disable highlighting. Also, lighten the F up. No one is spitting in your eye.
or for instance, i am doing a div which visitors need to double click to show another div... (kind of like a switch) but it's ugly to get the text highlighted when the divs gets double clicked...