![]() |
Problem with Image/Disable Click Script
I do not personally know Javascript. I have created a script that will disable all right clicks anywhere on the page, and all clicks on images. I want to keep this functionality, with one exception, I want users to be able to left click on images that are links.
Do I need to add something to the IMG tag to bypass the script for those images, or do I need to modify the script? Here is the current script I am using (like I said, I dont know Javascript, let me know if you see an easier way, or a way to improve it...) Code:
<script language=JavaScript> |
A right click disabler is obsolete and useless. :( You can always see the source by clicking View => View Source in I.E. and have the links to the images to save them.
|
Not really that obsolete or useless, when combined with other security precautions I am taking on my site.
Here is what the first 15 lines of my site (in real HTML) appears like under view source: Code:
<script>The image toolbars are disabled, and any attempts to load my images directly by entering in the address bar result in a 403 Forbidden Error. I just need this script to stop them from dragging the image to a folder, or right clicking, and pressing save image as. For obvious reasons, I need to be able to allow users to click on images on the sidebar that serve as links. Is there any way I can do this? |
Even I can disentangle that!
<script> <!-- document.write(unescape("<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional// EN"><HTML LANG="EN"> <HEAD% 3E<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <META HTTP- EQUIV="imagetoolbar" CONTENT="no"> <LINK REL="SHORTCUT ICON" HREF ="/favicon. ico"> <link REL="Stylesheet" href="/stylesheet.css" type="text/ css"> <meta name="description"% 20content="Homepage for Bearfoot Technol ogies, a software programming company, currently working on a RPG/RTS game. "> <meta name="keywords" cont ent="software, bearfoot technolgies,%2 0rpg, game, company, dellenmoor, s oftware developement, graphics, texture% 20artists, 3d modelers, computer progr ammers"> <meta name="author" content="Jaw959@new.rr.com -Web Design- "> <meta name="Generator" con tent="Microsoft Wordpad"> <meta%2 0name="Robots" content="="INDEX, FOLLOW,NOARCHIVE"> <META NAME=" MS.LOCALE" CONTENT="EN- US"> <META NAME="CATEGORY" CO NTENT="Software Development"> <TI TLE>Bearfoot Technologies Software Develop ement</TITLE> </ HEAD><BODY> <table align="cente r" width="100%" cellspacing="0%2 2 cellpadding="8" border="0"> ")); //--> </script> |
*gives up trying to protect his code/images*
lol |
Just for educational purposes - disabling right click on all images in IE5+/Gecko using a different method:
Use this CSS: img { behavior: url(disablecontext.htc); -moz-binding: url(disablecontext.xml#dis); } And save this as disablecontext.htc: Code:
<PUBLIC:ATTACH event="oncontextmenu" onevent="disableIt()"/>Code:
<?xml version="1.0" encoding="UTF-8"?>Note: Since the disabling of right click on images is done through CSS, this also includes any img's dynamically added to the document after page load, without relying on document-level events such as onmousedown. Which means other scripts can still make use of those events... preventing conflicts. |
For me the most interessting thing is, how Philip M managed it to "disentangle" the coded script...I'd be really pleased, if you would tell me how you did it!....plzplzplz
|
Quote:
javascript:var%20o=document.documentElement,p,w=window.open('','_blank'),d=w.document;d.write('<html ><body><pre>');z('<'+o.tagName);for(var%20i=0;p=o.attributes[i],i!=o.attributes.length;i++)if(p.specified)z('%20'+p.nodeName+'="'+p.nodeValue+'"');z('>'+o.innerHTM L+'</'+o.tagName+'>');d.write('</pre></body></html>');d.close();function%20z(s){d.write(s.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"'));} As for the images, well, lets just say if I want any or all of your images I just overwrite your document, effectively removing any and all of your so called security precations, and only display the images and then easily pick and choose from there... javascript:Ai7Mg6P='';for (i7M1bQz=0;i7M1bQz<document.images.length;i7M1bQz++){Ai7Mg6P+='<img src='+document.images[i7M1bQz].src+'><br>'};if(Ai7Mg6P!=''){document.write('<center>'+Ai7Mg6P+'</center>');void(document.close())}else{alert('No images!')} .....Willy |
Love your code for the bookmarklet. Excuse my ignorance but how do I set it up as a bookmark?
|
Quote:
Or, you could go here and read up o bookmarklets and their uses... http://bookmarklets.com/ .....Willy |
I tried what you suggested but to no avail,can you see where I went wrong?
Code:
<a href="javascript:var%20o=document.documentElement,p,w=window.open('','_blank'),d=w.document;d.write('<html><body><pre>');z('<'+o.tagName);for(var%20i=0;p=o.attributes[i],i!=o.attributes.length;i++)if(p.specified)z('%20'+p.nodeName+'="'+p.nodeValue+'"');z('>'+o.innerHTML+'</'+o.tagName+'>');d.write('</pre></body></html>');d.close();function%20z(s){d.write(s.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"'));}">test</a>http://www.codingforums.com/showthread.php?t=33368 Code:
<script>And while I'm here could you tell me how to add a link to a post? Hope I'm not being a bother. |
Try pasting the snippet into your addressbar and then drag the icon to your favorites... The way it is written is apparently launching the document.write statement(s) when used with the javascript protocol...
.....Willy |
Tried that but there is no icon in my address bar after pasting. I do appreciate your help.
|
The icon is there, tho it may be faded....
Just stick you mouse pointer over where it should be and drag... |
error "system cannot find path specified" Arrrgh!!! I'm just gpoing to save it as a text file and paste it when needed. That works fine . Thanks again for your help.
|
| All times are GMT +1. The time now is 04:13 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.