diff --git a/public/pdfjs/web/viewer.html b/public/pdfjs/web/viewer.html index d2b859e9..ad4f85df 100644 --- a/public/pdfjs/web/viewer.html +++ b/public/pdfjs/web/viewer.html @@ -50,6 +50,24 @@ See https://github.com/adobe-type-tools/cmap-resources 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() + } + }) }