是否可以阻止使用者擷取網頁螢幕截圖?


在瀏覽網際網路時,使用者可能需要擷取某些內容以便展示或向他人展示,但有時網頁上可能包含敏感資訊,開發者可能不希望使用者擷取螢幕截圖。

使用者可以同時按下功能鍵、Windows鍵和空格鍵來擷取螢幕截圖。在 MacOS 中,需要使用 Command + Shift + 3 來擷取螢幕截圖。

在這篇文章中,我們將瞭解如何阻止使用者擷取網頁螢幕截圖。

如何阻止使用者擷取螢幕截圖?

擷取螢幕截圖的命令無法停用,因為這些是內建功能,由作業系統控制。我們可以使用 HTML、CSS 和 JavaScript,但仍然無法阻止使用者擷取螢幕截圖。阻止使用者擷取螢幕截圖是一項困難的任務,因為使用者可以複製和貼上網站內容,也可以使用一些第三方軟體來做到這一點。

但是,我們可以使用一些方法來在一定程度上避免使用者擷取網頁螢幕截圖。

示例

在下面的示例中,我們插入了一些文字,然後將其放在一個 div 中,然後在 CSS 部分。之後,我們使用了媒體查詢並將顯示設定為 none。這樣,使用者可以看到內容,但無法列印螢幕。

<!DOCTYPE html>
<html lang="en">
<head>
   <title>Example of disabling the printing </title>
   <style>
      @media print {
         html,
         body {
            display: none;
         }
      }
   </style>
</head>
<body>
   <div>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been
      the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type
      and scrambled it to make a type specimen book. It has survived not only five centuries, but also the 
      leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with
      the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.
   </div>
</body>
</html>

示例

在下一個示例中,我們將透過在螢幕上顯示一條訊息來警告使用者不要複製或擷取網頁內容。

<!DOCTYPE html>
<html lang="en">
<head>
   <title>Example of disabling the printing </title>
   <style>
      html {
         user-select: none;
      }
   </style>
</head>
<body>
   <div>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry.
      Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, 
      when an unknown printer took a galley of type and scrambled it to make a type specimen book.
      It has survived not only five centuries, but also the leap into electronic typesetting,
      remaining essentially unchanged. It was popularised in the 1960s with the release of
      Letraset sheets containing Lorem Ipsum passages, and more recently with desktop 
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.
   </div>
</body>
</html>

在上面的程式碼中,我們使用了與前一個示例中相同的段落,這次在 CSS 部分,我們使用了 user-select 屬性並將它的值設定為 none。現在使用者可以在螢幕上看到內容,但無法選擇它。輸出將如下所示。

示例

在下一個示例中,我們將透過在螢幕上顯示一條訊息來警告使用者不要複製或擷取網頁內容。

<!DOCTYPE html>
<html lang="en">
<head>
   <title>Example of printing a warning message to the user </title>
   <script>
      alert("Please!! do not try to take any kinds of screenshot of the content");
   </script>
</head>
<body>
   <div>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry.
      Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, 
      when an unknown printer took a galley of type and scrambled it to make a type 
      specimen book. It has survived not only five centuries, but also the leap into 
      electronic typesetting, remaining essentially unchanged. It was popularised in 
      the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, 
      and more recently with desktop publishing software like Aldus PageMaker 
      including versions of Lorem Ipsum.
   </div>
</body>
</html>

在上面的程式碼中,我們再次使用了相同的段落,並使用了一行 JavaScript 程式碼,如果使用者試圖擷取網頁螢幕截圖,它將向用戶發出警告。

結論

完全阻止使用者擷取任何型別的螢幕截圖或複製然後貼上您的內容到其他第三方網站是不可能的。列印螢幕是一個內建功能,每個作業系統(如 Windows 和 MacOS)都提供此功能,並且這些功能無法停用,因為它們由作業系統控制。我們只能在一定程度上阻止使用者複製內容,而不能完全阻止。

更新於:2023年1月18日

17K+ 次瀏覽

啟動你的職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.