| <!DOCTYPE html> |
| <html lang="vi"> |
| <head> |
| <meta charset="UTF-8"> |
| <title>Test Excel Fix</title> |
| <script src="https://cdn.jsdelivr.net/npm/exceljs@4.4.0/dist/exceljs.min.js"></script> |
| </head> |
| <body> |
| <h2>🧪 Test Excel Multi-Download Fix</h2> |
| <button id="testBtn" onclick="testMultiDownload()">Test Excel Download</button> |
| <p id="status">Trạng thái: Chưa test</p> |
| |
| <script> |
| |
| var __VAI_BLOB_REGISTRY = { blobs: [], registry: [], isUnloading: false }; |
| var orig = URL.revokeObjectURL; |
| URL.revokeObjectURL = function(url) { |
| if (!__VAI_BLOB_REGISTRY.isUnloading && url && url.startsWith('blob:')) { |
| if (!__VAI_BLOB_REGISTRY.registry.find(e => e.url === url)) { |
| __VAI_BLOB_REGISTRY.registry.push({ url: url, revoked: false }); |
| } |
| return; |
| } |
| return orig.apply(this, arguments); |
| }; |
| |
| async function testMultiDownload() { |
| var btn = document.getElementById('testBtn'); |
| var status = document.getElementById('status'); |
| |
| try { |
| var wb = new ExcelJS.Workbook(); |
| var ws = wb.addWorksheet('Test'); |
| ws.getCell('A1').value = 'TEST MULTI-DOWNLOAD - ' + new Date().toLocaleTimeString(); |
| |
| var buf = await wb.xlsx.writeBuffer(); |
| var blob = new Blob([buf], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }); |
| var url = URL.createObjectURL(blob); |
| __VAI_BLOB_REGISTRY.blobs.push({ url: url }); |
| |
| var a = document.createElement('a'); |
| a.href = url; |
| a.download = 'test_' + Date.now() + '.xlsx'; |
| document.body.appendChild(a); |
| a.click(); |
| document.body.removeChild(a); |
| |
| status.innerHTML = '✅ Đã tải - ' + (new Date().toLocaleTimeString()) + '<br>Blob URL được bảo toàn, tải lại được!'; |
| } catch (e) { |
| status.innerHTML = '❌ Lỗi: ' + e.message; |
| } |
| } |
| </script> |
| </body> |
| </html> |