About handling Forbidden pictures default drag behavior action

Source: Internet
Author: User

This way, when I move the mouse, there is no function to trigger the OnMouseMove event binding. It's awkward to operate. Later I tidied up a bit. A total of three ways to solve this problem: It's not clear which way is better. When you have the ability to judge the pros and cons.

1, Document.images[i].ondragstart=function () {return false;};

Directly loop all the IMG tags on the page. The ondragstart event will then return FALSE, which disables the default drag action of the browser image. Feel here to traverse all IMG Tags: Individuals do not like to use this method. Feel that performance is not the best. Subjective think only.

2, Event.preventdefault ();

In Handler.onmousedown = function (event) {}, add Event.preventdefault ();

This method notifies the Web browser not to perform the default action associated with the event (if such an action exists). For example, if the type attribute is "submit", any event handle can be called at any stage of event propagation, and by calling the method, you can prevent the form from being submitted. Note that if the Cancelable property of the Event object is Fasle, there is no default action, or the default action cannot be blocked. In either case, calling the method has no effect.

3, This.setcapture && this.setcapture ();

In Handler.onmousedown = function (event) {} Add this.setcapture && this.setcapture ();

The SetCapture function sets the mouse capture in the specified window that belongs to the current thread. Once the window captures the mouse, all mouse input is directed at the window, regardless of whether the cursor is within the bounds of the window. Only one window can capture the mouse at a time. Individuals like this approach. Feel more reliable.

Other than that.. If you use a third method. Mouse capture is set at onmousedown, and when OnMouseUp is added, a release mouse is captured: Handle.releasecapture && handle.releasecapture () Or else it's going to go wrong under IE6. # Although in other modern browsers no problem #

About handling Forbidden pictures default drag behavior action

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.