2012-08-23 45 views
0

我使用的是我在Chrome資源文件(chrome://resources/js/util.js)中找到的此功能,並且在Google Chrome上運行良好。取消拖動和選擇事件

/** 
    * Disables text selection and dragging. 
    */ 
    function disableTextSelectAndDrag() { 
     // Disable text selection. 
     document.onselectstart = function(e) { 
     e.preventDefault(); 
     } 

     // Disable dragging. 
     document.ondragstart = function(e) { 
     e.preventDefault(); 
     } 
    } 

我想在Internet Explorer 8中取消這個事件,但是這不起作用。

如何在IE8中取消此事件?

回答

1

試試這個:

/** 
* Disables text selection and dragging on IE8 and below. 
*/ 
function disableTextSelectAndDragIE8() { 
    // Disable text selection. 
    document.body.onselectstart = function() { 
     return false; 
    } 

    // Disable dragging. 
    document.body.ondragstart = function() { 
     return false; 
    } 
}