usePreventSeeSourceCode
Introduction
禁止用户以任何方式查看网页源代码(Ctrl+S、Ctrl+U、Ctrl+Shift+I、Ctrl+Shift+C、点击 F12 和 点击鼠标右键)
Basic Usage
ts
import { usePreventSeeSourceCode } from '@flypeng/tool/browser';
const clear = usePreventSeeSourceCode(() => {
// To todo notice message give user
});
// The callback needs to be canceled at some time
clear();
Type Declaration
ts
/**
* 禁止用户以任何方式查看网页源代码(Ctrl+S、Ctrl+U、Ctrl+Shift+I、Ctrl+Shift+C、点击 F12 和 点击鼠标右键)
* @param callback
* @returns
*/
declare function usePreventSeeSourceCode(callback: () => void): () => void;
Online Demo
usePreventSeeSourceCode
阻止默认方法并单击键盘快捷键F12、Ctrl+S、Ctrl+U、Ctrl+Shift+I、Ctrl+Shift+C或Right。单击无响应
<script lang="ts" setup>
import { usePreventSeeSourceCode } from '@flypeng/tool/browser';
import { onMounted, onUnmounted } from 'vue';
let clear;
onMounted(() => {
clear = usePreventSeeSourceCode();
});
onUnmounted(() => {
clear();
});
</script>
<template>
<p>阻止默认方法并单击键盘快捷键F12、Ctrl+S、Ctrl+U、Ctrl+Shift+I、Ctrl+Shift+C或Right。单击无响应</p>
</template>