在剃须刀中禁用复制和粘贴

Disable copy & paste in razor

在我看来,有没有办法禁止从 table 复制数据?我有一个带有 table 的剃刀页面,我用数据填充它,但我试图禁用用户复制数据的选项。

@page "/products"

@attribute [Authorize]

@inject NavigationManager NavigationManager
@inject IViewProductsByNameUseCase ViewProductsByNameUseCase

<h3>Product List</h3>
<br/>

<ViewProductsComponent OnSearchProducts="OnSearchProducts"></ViewProductsComponent>

@if (listProducts != null)
{
    <table class="table">
        <thead>
            <tr>
                <th>Name</th>
                <th>Home place</th>
                <th>Expiration</th>
                <th>Phone number</th>
                <th>Tea</th>
                <th>Local</th>
                <th>App</th>
                <th>Company /Lease</th>
                <th>Road time</th>
                <th>Notes</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            @foreach(var product in this.listProducts)
            {
                <ProductItemComponent 
                    Product="product"
                    OnProductDeleted="OnProductDeleted"></ProductItemComponent>
            }
        </tbody>
    </table>    
}
<br/>
<button type="button" class="btn btn-primary" @onclick="AddProduct">Add Product</button>

我选择了产品,我可以轻松复制它。可以以某种方式禁用复制吗?

Is there a way to disable copying data from a table in my view?

没有

您不能使用 DRM HTML。

您无法控制 web-browsers 如何显示或与 HTML 互动。

否则,AdBlocker 还能如何工作?

你无法完全阻止它。但是您可以使复制变得更加困难。为此,您可以使用 JavaScript 代码来阻止使用 right-click、double-click 和键盘快捷键。

您可以使用以下JS函数来处理:

<script>

    if (document.layers) {
        document.captureEvents(Event.MOUSEDOWN);
        document.onmousedown = clickNS4;
    }
    else if (document.all && !document.getElementById) {
        document.onmousedown = clickIE4;
    }

    $('body').bind('cut copy paste', function (e) {
        e.preventDefault();
        return false;
    });

    $("body").on("selectstart", function (e) {
        e.preventDefault();
        return false;
    });

    $("body").on("dragstart", function (e) {
        e.preventDefault();
        return false;
    });

    $("body").on("drop", function (e) {
        e.preventDefault();
        return false;
    });

    $(document).keydown(function (event) {
        if (event.ctrlKey == true && event.which == '86') {
            event.preventDefault();
            return false;
        }

        if (event.ctrlKey && (event.keyCode === 83 || event.keyCode === 65)) {
            event.preventDefault();
            return false;
        }
        else if (event.ctrlKey && event.keyCode === 80) {
            event.preventDefault();
            return false;
        }
    });

    $("body").addClass('unselectable');
</script>

你的 unselectable class 看起来像:

.unselectable {
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

以上scriptcss将禁用复制等方面。您可以根据需要定制它们。