是否可以阻止在整个Web应用程序中拖放(移动/复制)图像或任何文件。
ex:我打开了我的Web应用程序并选择了一个系统映像并放入该Web应用程序,它正在打开一个完整大小的图像并将该URL显示为file:/// C:/ Users / Public / Pictures /Sample%20Pictures/Chrysanthemum.jpg
我想阻止它。
是否可能如果是,那么任何JS,如果没有,那么原因是什么?
答案 0 :(得分:0)
当用户尝试离开当前页面时会触发onbeforeunload事件。我在Chrome,Firefox和IE 9上进行了测试 - 如果用户将文件放入窗口,它也会触发。所以这可能对你有用。这显然取决于Javascript,不能保证启用。所以不要依赖它。
E.g。用jquery:
$(function(){
$(window).bind('beforeunload', function(){
return 'Really leave page?';
});
});
如果用户离开页面,它也会触发,因此在实践中这可能有点不方便。
答案 1 :(得分:0)
$(document).bind({
dragenter: function (e) {
e.stopPropagation();
e.preventDefault();
var dt = e.originalEvent.dataTransfer;
dt.effectAllowed = dt.dropEffect = 'none';
},
dragover: function (e) {
e.stopPropagation();
e.preventDefault();
var dt = e.originalEvent.dataTransfer;
dt.effectAllowed = dt.dropEffect = 'none';
}
});
答案 2 :(得分:0)
您应该在HTML文档的头部插入以下代码,即在代码之间插入。
<SCRIPT LANGUAGE="JavaScript">
<!-- Disable
function disableselect(e){
return false
}
function reEnable(){
return true
}
//if IE4+
document.onselectstart=new Function ("return false")
document.oncontextmenu=new Function ("return false")
//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
//-->
</script>