Hello, I'm not terribly good at JS, just have a footing in it, it is the last language that I got my hands on (Went PHP before JS) but anyways, I'm just seeking a little help. I need to be able to stop someone from dragging an image to their browser url, or wherever they chose to drag it and I have solved that problem by using: onmousedown="return false;" Code (markup): in the image element. Though currently it is being done manually, I need it to be done dynamically, and this needs to work cross site or else I would just do it with PHP, but I need to use JS. Basically I am thinking of using something like: function noDrag() { if(document.getElementByTagName("img") == true) { //Append onmousedown="return false;" } } noDrag() Code (markup): Is that at anyway possible with JS? Can I append the last bit (onMouseDown) dynamically to all images on a page? Thanks for any help. Edit: The images do not have any specific id/class so that is why I am pulling by the getElementByTagName.
wow. this one took me a while to wrap my brain around it, but it was a good challenge. i posted an example of it in action for 4 images here: demetri-media.com/JavaScript/javaEnlargeImage.html the first 2 images also have mouseover and mouseouts to change their size dynamically. the function i wrote to have mousedown=return false for all also enlarges the 3rd image too through its css style. the input button will change all the images at once ( well, looped to do it ) to onmousedown = return false. pretty slick. now of course if you are trying to protect your images, you know you can't really do it at all. & this trick just keeps some honest people honest. for this they just have to disable their javascript working in thier browser, and voila, no more protection. or of course just take a screen shot.... anyway, here is the code that made it work the input button onclick calls the fun1() function : function fun1(){ var imgs=document.getElementsByTagName("img"); for (var i=0;i< imgs.length;i++) { imgs[i].onmousedown = function(){ this.blur(); return false ; } imgs[2].style.height = "60px"; } } Code (markup):