| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>正在打开 PDF...</title>
- <style>
- body {
- font-family: 'Microsoft YaHei', sans-serif;
- display: flex;
- justify-content: center;
- align-items: center;
- height: 100vh;
- margin: 0;
- background: #F5F5F7;
- }
- .container {
- text-align: center;
- padding: 2rem;
- }
- .spinner {
- border: 4px solid #f3f3f3;
- border-top: 4px solid #3498db;
- border-radius: 50%;
- width: 40px;
- height: 40px;
- animation: spin 1s linear infinite;
- margin: 0 auto 1rem;
- }
- @keyframes spin {
- 0% { transform: rotate(0deg); }
- 100% { transform: rotate(360deg); }
- }
- .hidden {
- display: none;
- }
- </style>
- </head>
- <body>
- <div class="container">
- <div class="spinner"></div>
- <p>正在打开 PDF 文件...</p>
- </div>
-
- <!-- 使用隐藏的 <a> 标签,通过自动点击来打开 PDF(避免浏览器拦截) -->
- <div id="pdf-links" class="hidden">
- {% for url in pdf_urls %}
- <a href="{{ url }}" target="_blank" id="pdf-link-{{ loop.index0 }}"></a>
- {% endfor %}
- </div>
-
- <script>
- // 使用 <a> 标签自动点击来打开 PDF(避免浏览器拦截)
- const pdfUrls = {{ pdf_urls | tojson }};
- console.log('PDF URLs:', pdfUrls);
-
- if (pdfUrls && pdfUrls.length > 0) {
- // 立即打开第一个(用户点击触发的,不会被拦截)
- const firstLink = document.getElementById('pdf-link-0');
- if (firstLink) {
- firstLink.click();
- }
-
- // 延迟打开其他的(在用户交互的上下文中,通常不会被拦截)
- pdfUrls.forEach((url, index) => {
- if (index === 0) return; // 第一个已经打开了
-
- setTimeout(() => {
- const link = document.getElementById(`pdf-link-${index}`);
- if (link) {
- link.click();
- } else {
- // 如果找不到链接,尝试用 window.open(可能被拦截)
- window.open(url, '_blank');
- }
- }, index * 200);
- });
-
- // 2 秒后提示可以关闭
- setTimeout(() => {
- document.querySelector('.container p').textContent = 'PDF 已在新标签页打开,可以关闭此窗口';
- }, 2000);
- } else {
- document.querySelector('.container p').textContent = '没有找到 PDF 文件';
- }
- </script>
- </body>
- </html>
|