-Sky- 0 Report post Posted September 16, 2008 Disabling Right Click Function.Is it possible in any way to prevent people from right-clicking on my sites pages? Also, I'd like to know if It's possible to create an HTML based Navigation bar. :)Could someone/anyone help me with this function?I'd like to put an HTML No-Right-Click script that comes up with an error saying: "Bad move there. Right-Clicking is not allowed.".Thanks. Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted September 17, 2008 Disabling right click to prevent users from viewing Source code or protecting images is not a good idea for several reasons. See these links:http://forums.xisto.com/no_longer_exists/http://forums.xisto.com/no_longer_exists/ Share this post Link to post Share on other sites
-Sky- 0 Report post Posted September 17, 2008 Oh. OK, thanks Jim. So there's no way to hide my content on my sites pages then?I'm pretty sure copyright won't stop them either.Second question:Can anyone help me with a Navigation bar for my site with HTML?Thankyou. Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted September 17, 2008 Can anyone help me with a Navigation bar for my site with HTML?Start a new Topic in the HTML Sub-forum, please. Share this post Link to post Share on other sites
rvalkass 5 Report post Posted September 17, 2008 Oh. OK, thanks Jim. So there's no way to hide my content on my sites pages then?I'm pretty sure copyright won't stop them either. Due to the way the web works, it's impossible to totally mask the code behind a site. The browser needs to be able to read the code behind the site so that it can actually display it. If the code was hidden then the browser wouldn't be able to use it to make the page.As for copyright - you can copyright the content of the pages (the text, images, sounds, videos, whatever) but not really the HTML code behind it. Share this post Link to post Share on other sites
Nabb 0 Report post Posted September 17, 2008 You can OBFUSCATE your html code, but not HIDE it.Firstly, you should be able to take a look at random html by simply pressing ctrl+U, or adding view-source: to the url.If you wish to obfuscate the code, what you should be doing is encrypting the file with some form of encryption, and then have this as a variable in javascript. Then you would need to have the javascript decrypt the ciphertext and display it with document.write(stuff).However this would pose a problem to those with javascript off... Share this post Link to post Share on other sites
rvalkass 5 Report post Posted September 17, 2008 If you wish to obfuscate the code, what you should be doing is encrypting the file with some form of encryption, and then have this as a variable in javascript. Then you would need to have the javascript decrypt the ciphertext and display it with document.write(stuff).However this would pose a problem to those with javascript off... Not only would people with JavaScript turned off see nothing, but these 'encryption' methods are futile at best. At worst, they make the load times of your pages skyrocket, and annoy users. All people need to do is view the source, and run the JavaScript locally, but this time output the result so that it can be read... Suddenly all your code appears. Share this post Link to post Share on other sites
Nabb 0 Report post Posted September 17, 2008 Well it's obfuscation. You can't stop someone from getting the code because the browser needs to interpret it.Actually can't you ctrl-a, ctrl-c, ctrl-v in a WYSIWYG editor... Share this post Link to post Share on other sites
PilzzE 0 Report post Posted September 17, 2008 If you want to protect your photo's/images use a watermark on them,You can do that in Photoshop or with a php script. PHP watermark tutorialPeople hate it when you disable functionalities and pop up messages.Altough if you use something like a .hta file then it provides some security. But on websites it is a !!NO!!. Share this post Link to post Share on other sites
minimcmonkey 0 Report post Posted September 17, 2008 (edited) Ok, well mopst people will tell you to use a piece of javascript.But this is much less useful, than a simple attribute in the <body> tag of your page.A javascript type defence has many problems- Someone may disable javascript to get round it- you are not protected against people pressing the menu button on their keyboard- you can chnage mouse buttons to right click, and most scripts only protect against button 2- people with three button mice, often get round these scriptsyou said you wanted an alert saying "bad move" or something, so i will give you code to disable the context menu, then to cause the alert, this is most effective.To cause the context menu to not-apear when someone right clicks on your page, simply, use this in your <body> tag. oncontextmenu="return false;" your body tag may look like this:<body bgcolor="112233" onmousedown="coordinates(event)" oncontextmenu="return false;"> Ok, this will not disable the "page" menu in IE 7 ect. I dont think there is a way to disable that, but it will disable the context menu.Now for the script.This code will cause an alert to appear, if any mouse button is clicked, other than button one.<script type="text/javascript">function coordinates(event){if (event.button==1) {}else {alert("bad move");}}</script>This should be placed in the head section, and run onmousedown.However, this script will say "bad move" even on click of the middle button, fo people who want to use autoscroll, will not be le to, and will have to scroll manually, with the mouse wheel.This code, will only say "bad move" if button two is pressed, remember, this is even easier to evade than the previous script.<script type="text/javascript">function coordinates(event){if (event.button==) {alert("bad move");}else {}}</script> Here is a sample of what the page could look like:<html><head><script type="text/javascript">function coordinates(event){if (event.button==1) {}else {alert("bad move");}}</script><title>my Photo Gallery</title></head><body bgcolor="112233" onmousedown="coordinates(event)" oncontextmenu="return false;"><p>Content goes here</p></body></html> Note that none of the scripts above will cause the alert if the menu buttonis pressed, if you want that to trigger the alert, replaceoncontextmenu="return false;"with something like oncontextmenu="functionabc()";Then create a javascript function with that name, that causes an alert like this:<script type="text/javascript">function functionabc(){alert("Bad move")}</script> Remember that you cant ever really stop people steeling your code or imagesm, there is always a way, i wont list the ways, but im sure you can imagine.one great way round this, is simple text.Simply make sure, you write at the bottom of the page, what people are allowed to use your images/content for, and make sure you put author information in HTML comment tags in your code.You said you wanted to make a navigation menu, I am happy to help you, but could you provide some more information as to what you want.(do you want to use images, do you want something to change colour when you hover over it ect.) Edited September 17, 2008 by minimcmonkey (see edit history) Share this post Link to post Share on other sites
gara456 0 Report post Posted October 14, 2008 I think we never make a site like a google and yahoo. i have a code that disable the right click. Here is the script to disable right clickPlace this script on body<script language="JavaScript" type="text/JavaScript">function disableRightClick(e){var message = " Ooopsss!!! \rRight click is disabled";if(!document.rightClickDisabled) // initialize{if(document.layers){document.captureEvents(Event.MOUSEDOWN);document.onmousedown = disableRightClick;}else document.oncontextmenu = disableRightClick;return document.rightClickDisabled = true;}if(document.layers || (document.getElementById && !document.all)){if (e.which==2||e.which==3){alert(message);return false;}}else{alert(message);return false;}}disableRightClick();</script>Reply With Quote but i want to know that can we change the content of right click.thanks Share this post Link to post Share on other sites
iGuest 3 Report post Posted May 7, 2009 Disable Right click and Special charecter validation.Disabling Right Click Functionvar message="Function Disabled!";/////////////////////////////////// function clickIE4(){ if (event.Button==2){ alert(message); return false;} } function clickNS4(e){ if (document.Layers||document.GetElementById&&!document.All){ if (e.Which==2||e.Which==3){alert(message); return false;} } } if (document.Layers){document.CaptureEvents(Event.MOUSEDOWN); document.Onmousedown=clickNS4; } else if (document.All&&!document.GetElementById) { document.Onmousedown=clickIE4; } document.Oncontextmenu=new Function("alert(message);return false") function validateSpecialChars(myStringID) { var strToSearch = myStringID.Value; var illegalChars = "'<>!$%&*`~"; for (var I = 0; I < strToSearch.Length; I++) { if (illegalChars.IndexOf(strToSearch.CharAt(I)) != -1) { alert ("This special Charecter is not allowed!"); //document.GetElementById(crtl).Value = ''; myStringID.Value=''; myStringID.Focus(); return false;} } } -reply by sabeerpasha Share this post Link to post Share on other sites
Dave Morton 0 Report post Posted June 9, 2009 (edited) As has been stated previously, disabling the right-click is more or less a waste of time for you, and an annoyance to the page viewer. There are a LOT of reasons to allow the user to right-click on your page, and all it takes to remove any imposed restriction is to disable javascript for that page. If you want to protect your images, I suggest using a watermark, as well. Every image in my gallery on my site is watermarked prior to presentation, with a copyright, the date and time, and sometimes, even the IP address that it's being viewed at. If it's your code itself that you want to hide, even obfuscation won't deter the most hardcore site hound (myself included), since the more you try to make the code unreadable by human eyes, the harder we try to bypass your measures. However, if you want to hide your code, and you're using PHP, I DO have a (highly silly) method for you to do so: (explanation within code documentation) <?php /////////////////////////////////////////////////////////////// // Security.php // // Page source and context menu protection // // Simple php extension module // // Written by Dave Morton // // Š2003 Geek Cave Creations - all rights reserved /////////////////////////////////////////////////////////////////* usage:Either at, or very near the begining of your code, place the following line:include("path/to/security.php");Then, place the next line after any generated headers, but before the <HTML> tag, the following line:print "$crap"; //(echo works, too, or any other method of printing that you like)For codeSafe, place it somewhere before the </head> tag, or as close to the top of the page as you can:print "$codeSafe";That's all there is to it! I know it's not perfect, and that $crap is NOT foolproof (or dialup friendlyfor that matter), but it's bound to reduce code and image (or other resourcees) theft, and that's a good thing!*///////////////// Page Security controls ////////////////// /*NOTE: The two code security features below work in different ways to help keep folks from viewingyour(read: MY) code, thus reducing the chance of theft. They work in the following manner: 1.) $crap: (WARNING!!! NOT dialup friendly!) $crap calls a routine that generates random screen garbage within an HTML comment tag. It's designed to create only characters that will actually print to a browser page, so as not to "break" HTML code valitators, such as the one I use at w3.org 2.) $codeSafe: $codeSafe calls a routine that prints a javascript section that disables the right-click and context menu features of the browser. It's basically the same one a lot of sites use, so it's nothing special, but it does seem to work as intended. Now, I know that folks can just disable scripts, and those who are patient enough to actually go through the HTML source line by line can still obtain the code, but the 2 measures enabled here will keep out about 99.5% of all folks who initially attempt to view the code or steal images, which is good enough for me.*/// makeGarbage variables:$crapMin = 10000; //Minimum amount of random characters to print (about 9.7k)$crapMax = 30000; //maximum amount of random characters to print (about 29.3k)$crMin = 100; //minimum amount of random characters between carriage returns$crMax = 500; //maximum amount of random characters between carriage returns$crap = "";$smallCrap = "";$codeSafe = "";$crap = makeGarbage(); // Comment out this line to remove code theft prevention$smallCrap = makeGarbage(300,1000,80,350); // Comment out this line to remove code theft prevention$codeSafe = getCodeSafe(); // Comment out this line to remove context menu prevention// modifyable variable parameters for adjusting the amount of crap to print\// getCodeSafe variables:$csMsg = "Code Theft Stinks!";$csAlert = 'alert(msg);'; //remove comments at begining of the line to use the alert system// Please don't modify the code belowfunction makeGarbage($crapMin = 10000, $crapMax = 30000, $crMin = 100, $crMax = 500) { $tmp = srand(); // Seeds the RNG $len = rand($crapMin, $crapMax); // Sets the amount of screen garbage to be printed $count1 = $count2 = 0 ; $out = "<!--"; // Initialize some variables while ($count1 < $len) { // Starts the loop $char = rand(32, 255); if (($char >=127) and ($char <= 159)) { // Some characters cannot be used, so ignore the bad ones $char = 0; } $char = ($char != 45) ? $char : 44; // See last comment $char = ($char != 60) ? $char : 63; // See last comment (Not THAT one! The one BEFORE it!) $char = ($char != 62) ? $char : 61; // See last comment (Um... Do I REALLY have to... N'mind.) $char = ($char > 0) ? chr($char) : ""; $out .= $char; $count1++; $count2++; // Increment our variables $rCRLF = rand($crMin, $crMax); // If the line is too long, add a NewLine if ($count2 > $rCRLF) { $count2 = 0; $out .= "\n"; } } // And back to the beginning! $out .= "-->\n"; return $out;}function getCodeSafe() { global $csMsg, $csAlert; $out = <<<END_CODESAFE<script language="JavaScript1.2" type="text/javascript"> var msg = "$csMsg"; if(document.layers) window.captureEvents(Event.MOUSEDOWN); function no_click(e){ if (navigator.appName == 'Netscape' && ( e.which == 2 || e.which == 3)) { $csAlert return false; } if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) { $csAlert return false; } } window.onmousedown=no_click; document.onmousedown=no_click; document.oncontextmenu=new Function("return false"); </script>END_CODESAFE; return $out;}?> Notice that the code is well documented, making it easy to use. I wrote this several years ago, when I was still ignorant of certain aspects of web design. It also has a generic JS routine to disable right-click, but I mostly used the script to make it difficult to allow people to rip off my pages and claim them as their own. It was only later, while learning about Search Engine Optimization that I discovered the lack of wisdom in using these features. My advice today is: If you don't want people to rip off your code/images/content, then don't post it. That's the only truly sure way to protect it. But where's the fun in that?[edit] In order to test this out, I've set up a page at Geek Cave Creations SecTest Page to demonstrate the script. To view the source in FF, hit CTRL-U. In IE, go to View => Source.[/edit] Edited June 9, 2009 by Dave Morton (see edit history) Share this post Link to post Share on other sites