[update] 修改pdf预览禁用右键

This commit is contained in:
lideqin
2024-06-28 17:35:49 +08:00
parent 74a8af2a3c
commit 943d7df0b3
+40 -26
View File
@@ -36,38 +36,52 @@ See https://github.com/adobe-type-tools/cmap-resources
<script src="viewer.js"></script> <script src="viewer.js"></script>
<script> <script>
if (!window.frameElement) { if (!window.frameElement) {
// 禁用F12
document.addEventListener('keydown', function(event) { document.addEventListener('keydown', function(event) {
if (event.key === 'F12' || event.keyCode === 123) { if (event.key === 'F12' || event.keyCode === 123) {
event.preventDefault() event.preventDefault()
} }
}) })
// 禁止右键
document.oncontextmenu = function (event) {
event.returnValue = false
console.log('document.oncontextmenu')
}
// 页面不是通过iframe嵌入的 // 页面不是通过iframe嵌入的
const h = window.innerHeight // const h = window.innerHeight
const w = window.innerWidth // const w = window.innerWidth
window.onresize = function () { // window.onresize = function () {
if (h !== window.innerHeight || w !== window.innerWidth) { // const height = window.innerHeight
window.open(window.location.href, '_blank') // const width = window.innerWidth
window.close() // const outerHeight = window.outerHeight
} // const outerWidth = window.outerWidth
} // console.log('innerWidth' + width , 'innerHeight', height)
// 检测是手动刷新页面 // console.log('outerWidth' + outerWidth , 'outerHeight', outerWidth)
function isPageRefresh() { // // window.alert('innerWidth' + width + ',innerHeight' + height + ',outerWidth' + outerWidth + ',outerHeight' + outerWidth)
const navigationEntries = window.performance.getEntriesByType('navigation') // if ((h !== height && height < outerHeight - 100) || (w !== width && width < outerWidth - 20)) {
if (navigationEntries.length > 0) { // // window.alert('长宽变化要重新打开了')
const lastEntry = navigationEntries[navigationEntries.length - 1] // window.open(window.location.href, '_blank')
// 如果最后一个性能条目的类型是 "reload",则表明页面可能是通过手动刷新加载的 // window.close()
return lastEntry.type === 'reload' // }
} // }
return false // // 检测是手动刷新页面
} // function isPageRefresh() {
window.addEventListener('load', function() { // const navigationEntries = window.performance.getEntriesByType('navigation')
if (isPageRefresh()) { // if (navigationEntries.length > 0) {
console.log('页面可能是手动刷新的') // const lastEntry = navigationEntries[navigationEntries.length - 1]
// 在这里处理页面刷新的逻辑 // // 如果最后一个性能条目的类型是 "reload",则表明页面可能是通过手动刷新加载的
window.open(window.location.href, '_blank') // return lastEntry.type === 'reload'
window.close() // }
} // return false
}) // }
// window.addEventListener('load', function() {
// if (isPageRefresh()) {
// console.log('页面可能是手动刷新的')
// // 在这里处理页面刷新的逻辑
// window.open(window.location.href, '_blank')
// window.close()
// }
// })
} }
</script> </script>