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