首页 > 解决方案 > 如何不显示来自 ctrl + u 的代码源

问题描述

所以我在网上冲浪,发现了很酷的网站。当我想克隆他的设计时,我无法通过 (ctrl+u) 看到源代码。它没有显示。我如何让它像他们一样。

网站->来源

看起来我无法点击链接..这是原始的view-source:https://www.dte.web.id/

标签: htmlcssxhtmlblogger

解决方案


使用下面的代码,您将禁用该功能 (ctrl + u)。重要的是要知道它不会阻止任何用户通过“查看源代码:链接”查看源代码

<script type="text/javaScript">
function testKeyCode(e) {
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
var e = e || window.event;
           if (e.ctrlKey &&
                  (e.keyCode === 67 ||
                   e.keyCode === 86 ||
                   e.keyCode === 85 ||
                   e.keyCode === 117)) {
    alert('This website is protected against attempts to clone. Your IP has been duly recorded on our server and if you persist it will be forwarded to the competent authorities');
   return false;
   } else {
    return true;
   }
}
document.onkeydown = testKeyCode;
</script>

推荐阅读