Home >Web Front-end >Front-end Q&A >How to disable drag and drop in html

How to disable drag and drop in html

藏色散人
藏色散人Original
2021-05-25 10:32:485934browse

htmlHow to disable drag and drop: first open the corresponding HTML code file; then use the "οndragstart="return false;"" method to disable mouse dragging.

How to disable drag and drop in html

The operating environment of this article: Windows7 system, HTML5 version, DELL G3 computer

Html disable drag and drop function

How to disable it Drag page elements out?

οndragstart="return false;"//禁止鼠标拖动,如拖动图片、连接等

For example:

<body οndragstart="return false;" οncοntextmenu="return false;">

How to disable dragging elements into the page?

<script>
document.ondrop = function(event) {
return false;
};
document.ondragenter  = function(event) {
return false;
};
document.ondragover  = function(event) {
return false;
};
</script>

Recommended learning: "HTML Video Tutorial"

The above is the detailed content of How to disable drag and drop in html. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn