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).
There are 2 possible solutions:
Remove "sandbox" header.
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
).