在瀏覽網路時,使用者可能會發現需要擷取某些內容以便向某人展示或展示,但有時網頁上可能存在開發人員可能不希望使用者對其進行螢幕截圖的敏感資訊。
使用者可以按下功能鍵以及Windows鍵和空白鍵來進行螢幕截圖。在 MacOS 中,我們必須使用指令、shift 和 3 來截取螢幕截圖。
在本文中,我們將了解如何阻止使用者對網頁進行螢幕截圖。
如何阻止使用者截圖?
無法停用截圖命令,因為這些是內建功能並由作業系統控制。我們可以使用 HTML、CSS 和 JavaScript,但仍然無法阻止使用者截圖。阻止用戶截圖是一項艱鉅的任務,因為用戶可以複製貼上網站內容,也可以使用一些第三方軟體來做到這一點。
但是,我們可以透過一些方法來在一定程度上避免使用者對網頁進行截圖。
範例
在下面的範例中,我們插入了一些文本,然後將其包含在 div 中,然後包含在 CSS 部分中。之後,我們使用媒體查詢並將顯示設為無。這樣,內容將對用戶可見,但用戶將無法列印螢幕。
<!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 等每個作業系統都提供的內建功能,而這些功能無法停用,因為它們由作業系統控制。我們只能在一定程度上阻止用戶複製內容,而不能超過此限度。
以上是是否可以阻止使用者對網頁進行截圖?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

CSS盒子陰影和輪廓屬性獲得了主題。讓我們查看一些在真實主題中起作用的示例,以及我們必須將這些樣式應用於WordPress塊和元素的選項。

Svelte Transition API提供了一種使組件輸入或離開文檔(包括自定義Svelte Transitions)時動畫組件的方法。

前幾天我只是和埃里克·邁耶(Eric Meyer)聊天,我想起了我成長時代的埃里克·邁耶(Eric Meyer)的故事。我寫了一篇有關CSS特異性的博客文章,以及


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

WebStorm Mac版
好用的JavaScript開發工具

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

Atom編輯器mac版下載
最受歡迎的的開源編輯器