AngularJS 1.5应用IE11下载失效伴DOM7011警告问题求助
Hey there, let's break down the issues you're facing and get that screenshot download working in IE11. First, let's clarify two key points:
- The DOM7011 warning is mostly a red herring here—it's triggered because AngularJS (specifically ngRoute) adds
onunloadhandlers which disable IE's back/forward caching, but this doesn't directly cause your download to fail. - Your current
$httpProvidercache settings are for AJAX requests, not frontend-generated blob downloads, so they won't fix this specific problem.
The Root Cause: IE11's Limited Blob/Download Support
Unlike Chrome and Firefox, IE11 doesn't support the standard <a> tag download attribute for blob URLs. Instead, it requires using Microsoft's proprietary msSaveBlob or msSaveOrOpenBlob methods to trigger file downloads from frontend-generated content.
Step-by-Step Solution
1. Update Your Screenshot Download Logic
Assuming you're using a library like html2canvas to capture the screenshot, modify your download code to handle IE11 specifically:
// Example: After capturing your canvas element function downloadScreenshot(canvas) { const fileName = 'user-data-screenshot.png'; canvas.toBlob(function(blob) { // Check for IE11/legacy Edge support if (window.navigator && window.navigator.msSaveOrOpenBlob) { // IE11-specific download method window.navigator.msSaveOrOpenBlob(blob, fileName); } else { // Standard method for Chrome/Firefox/modern browsers const downloadLink = document.createElement('a'); const blobUrl = URL.createObjectURL(blob); downloadLink.href = blobUrl; downloadLink.download = fileName; document.body.appendChild(downloadLink); downloadLink.click(); // Clean up to avoid memory leaks setTimeout(() => { document.body.removeChild(downloadLink); URL.revokeObjectURL(blobUrl); }, 100); } }, 'image/png'); // Specify your desired image format (png/jpeg) }
2. Addressing the DOM7011 Warning (Optional)
If you want to eliminate the warning (it doesn't break functionality, but can be annoying), you can override AngularJS's default onunload behavior that triggers BF cache disabling. Add this to your AngularJS run block:
myApp.run(['$rootScope', function($rootScope) { // Override the default onunload handler to prevent BF cache disabling in IE $rootScope.$on('$locationChangeStart', function() { if (window.addEventListener) { window.removeEventListener('unload', angular.noop); } else { window.detachEvent('onunload', angular.noop); } }); }]);
Note: This might have minor side effects on route cleanup in some edge cases, so test thoroughly in your app.
Why Your Original Code Didn't Work
The $httpProvider settings you added control caching for AJAX requests made via Angular's $http service. Since your download is generated entirely frontend-side (from a canvas screenshot), these settings have no impact on the download process.
Final Notes
- Test the IE11-specific code directly in IE11 (emulation tools in dev tools might not fully replicate the behavior).
- If you're using a different screenshot library, the core idea remains the same: check for IE11 and use
msSaveBlobinstead of the standard download link approach.
内容的提问来源于stack exchange,提问作者Chetna Gupta

