網頁中設定禁止查看原始碼(保護原始碼)

來源:互聯網
上載者:User

標籤:profile   als   fun   瀏覽器   設定   err   close   poster   sel   

開發網站的過程中有時我們不想讓客戶看到頁面的原始碼,甚至頁面上的文字內容都不想被複製,下面我們來看一下怎麼保護頁面內容
禁止查看頁面原始碼和禁止複製頁面中的文字
<body style=" oncontextmenu="return false" onselectstart="return false">

我們都知道即使設定禁止右鍵但是 點擊F12還是可以查看到原始碼,下面我們來設定禁止使用F12

<script>        function fuckyou() {            window.close(); //關閉當前視窗(防抽)            window.location = "about:blank"; //將當前視窗跳轉置空白頁        }        function ck() {            console.profile();            console.profileEnd();            //我們判斷一下profiles裡面有沒有東西,如果有,肯定有人按F12了,沒錯!!            if (console.clear) { console.clear() };            if (typeof console.profiles == "object") {                return console.profiles.length > 0;            }        }        function hehe() {            if ((window.console && (console.firebug || console.table && /firebug/i.test(console.table()))) || (typeof opera == ‘object‘ && typeof opera.postError == ‘function‘ && console.profile.length > 0)) {                fuckyou();            }            if (typeof console.profiles == "object" && console.profiles.length > 0) {                fuckyou();            }        }        hehe();        window.onresize = function () {            if ((window.outerHeight - window.innerHeight) > 200)                //判斷當前視窗內頁高度和視窗高度,如果差值大於200,那麼呵呵                fuckyou();        }</script>

使用上面的js代碼可以禁止使用F12,註:上面的js代碼不是我自己所寫,已經忘記是哪位大神所寫~~
最後我們知道圖片在瀏覽器中滑鼠只要一拖動就會儲存下來,但是背景圖片不會被拖動,下面代碼可以使頁面中的圖片禁止滑鼠拖動
&lt;body style="ondragstart="return false"&gt;

網頁中設定禁止查看原始碼(保護原始碼)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.