Prevent Internet Explorer’s Default Image Dragging Action
Since the web is moving more and more toward a drag and drop world, it's important to prevent Internet Explorer's default dragging action when attempting to drag an image. JavaScript makes this possible.
Using MooTools
document.ondragstart = function () { return false; };
Happy dragging and dropping!
![9 Mind-Blowing Canvas Demos]()
The <canvas>
element has been a revelation for the visual experts among our ranks. Canvas provides the means for incredible and efficient animations with the added bonus of no Flash; these developers can flash their awesome JavaScript skills instead. Here are nine unbelievable canvas demos that...
![39 Shirts – Leaving Mozilla]()
In 2001 I had just graduated from a small town high school and headed off to a small town college. I found myself in the quaint computer lab where the substandard computers featured two browsers: Internet Explorer and Mozilla. It was this lab where I fell...
![NSFW Blocker Using MooTools and CSS]()
One of my guilty pleasures is scoping out the latest celebrity gossip from PerezHilton.com, DListed.com, and JoBlo.com. Unfortunately, these sites occasionally post NSFW pictures which makes checking these sites on lunch a huge gamble -- a trip to HR's office could be just a click away.
Since...
![Fancy Navigation with MooTools JavaScript]()
Navigation menus are traditionally boring, right? Most of the time the navigation menu consists of some imagery with a corresponding mouseover image. Where's the originality? I've created a fancy navigation menu that highlights navigation items and creates a chain effect.
The XHTML
Just some simple...
Nice and simple. Just the way I like it!
I think your header there is a touch misleading. Nothing in that code snippet requires moo unless
ondragstart
is a MooTools added event.The MooTools version I imagine would look something like..
just my two bits.
@David Nice tip – short, but useful!
@Bryan – You are correct…
document.ondragstart is actually a JScript (Microsoft) only method. I am pretty certain it is not defined in the ECMAScript documentation. David’s script will work just fine in non MS browsers too, though, since JavaScript allows object augmentation. In non MS browsers, this script will simply add a new method object to the document object – which is mostly inconsequential. I suppose if you’re concerned about modifying the document hash, you could always try something like this:
if(document.ondragstart)
{
document.ondragstart = function() { return false; };
}
Thanx a lot for the tip it helped me a lot !
J
Im trying to prevent a component of my navi bar to not be dragged.
I’m using:
So why does this not prevent the image from being dragged in FF?
Thank you for this concise and helpful tidbit. It saved me additional searching. For those looking to inhibit dragging behavior on a individual element (an image in this example) rather than the whole document, try: <img src=”blah.jpg” ondragstart=”return false” />
Thank you! Finally a solution that is simple, and works on all browsers!
Hey I have the solution that all browsers work with… doesn’t work for firefox if you have a lot of code so I came up with this. By adding an “!important” statement it tells it that it is the most important code to find so it refers to it before everything else:
Also prevents right clicking and makes it un-selectable.
We had this enabled in a .js file then had each page call on the file. It worked great but now we noticed one site copied an entire page of ours so we tried to do it our self in IE9 and was able to copy the same info.
Does that mean IE9 now ignores it or is there a bug in IE9?
Please give me an example. GitHub or empty page.
Case:
I have two pages (in a different windows, for ex: ie 10)
1 page with code
document.ondragstart = function(){return false;};
(or other event)2d page with img
then i drag image to first window.
Result your method does not work.
Same here – it seems this method doesn’t work in any browser, not even IE11. Dragging and dropping image results in leaving page and going to image file. Anyone know of a workaround?