1

我想阻止用户从网格单元格中复制数据

我用过css

td.dxgv
{   
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-user-select: none;
}

这在 Google Chrome、Moz FireFox、Opera 中运行良好,但在 IE 中不行


在此处输入图像描述

我希望用户不能像图片上那样选择整个网格

我写的css不能只在IE中工作

4

2 回答 2

2

我找到了解决方案

<div id="applicationList" class="applicationList" onselectstart="return false;">
        @Html.Partial("_List", Model)
</div>

这也适用于 IE

于 2012-08-06T11:53:36.747 回答
1

如果你可以使用 jquery,你可以从 pkarl尝试这个解决方案:

<script src="http://www.google.com/jsapi"></script> 
<script type="text/javascript">
    google.load("jquery", "1");
</script>

<script type="text/javascript"> 

$(function() {

    // We check for a text selection when someone right-clicks
    $(document).bind('contextmenu', checkSelection);

    // We also check for a text selection if ctrl/command are pressed along w/certain keys
    $(document).keydown(function(ev) {

        // capture the event for a variety of browsers
        ev = ev || window.event;

        // catpure the keyCode for a variety of browsers
        kc = ev.keyCode || ev.which;

        // check to see that either ctrl or command are being pressed along w/any other keys
        if((ev.ctrlKey || ev.metaKey) && kc) {

            // these are the naughty keys in question. 'x', 'c', and 'c'
            // (some browsers return a key code, some return an ASCII value)
            if(kc == 99 || kc == 67 || kc == 88) {
                return checkSelection()
            }

        }

    });

})

// check to see if anything is currently highlighted by the visitor. If so, return false.
function checkSelection() {
    if (window.getSelection) { var userSelection = window.getSelection(); } 
    else if (document.selection) { var userSelection = document.selection.createRange(); }
    if(userSelection != '') return false;
}

于 2012-08-06T08:43:22.127 回答