Search code examples
internet-explorer-11sandboxcontent-security-policy

"Save as" dialog is not shown in IE11 when page is loaded as "sandbox"


I try to download file on click.

<!DOCTYPE html>
<html>
<body>
<a onclick="handler()">Click Here</a>
<iframe id="mmain" name="mmain" height="400" width="400"></iframe>
<script>
function handler() {
document.getElementById("mmain").src = "http://localhost:8083/myapp/test_content";
}
</script>
</body>
</html>

The test_content is generated with the following headers:

 response.setHeader("Content-Type", "text/plain");
 response.setHeader("Content-Disposition", "attachment");
 response.setHeader("X-Content-Security-Policy", "sandbox;");

However, Save As dialog is not shown in IE11 (works OK in Chrome and Firefox).


Solution

  • There are 2 possible solutions:

    1. Remove "sandbox" header.

    2. Use <a href="http://localhost:8083/myapp/test_content" target="mmain">Click Here</a> instead of javascript (target doesn't have to be frame name, it can be, for example, _self).