Some days ago i mentioned a problem with the IE7: When you open a new window with JavaScript (window.open) to just download a file from a server the Internet Explorer won’t download the file - under certain circumstances.
Problem example
So what happens? Just assume the following download.php-script on the server:
<?php
header(”Content-Type: application/pdf”);
header(”Content-Disposition: attachment; filename=AuthorityAlliances.pdf”);
header(”Cache-Control: must-revalidate, post-check=0, pre-check=0″, true);
header(”Expires: 0″);
readfile(”AuthorityAlliances.pdf”);
?>
Now put the following code within a html-file:
<html>
<head>
<script>
<!–
function go(jump){
window.open(jump);
}
–>
</script>
</head>
<body>
<form name=”Downloads”> ‘
<select name=”Downloads” size=”1″ onchange=”if (this.form.Downloads.options.selectedIndex != 0) {go(this.value);}”>
<option selected value=”">Select</option>
<option value=”http://yourserver/download.php”>PDF</option>
</select>
</form>
</body>
</html>
With the default Internet Explorer 7 installation selecting the entry in the combobox will work fine, if you test it locally - but if you upload these files to a server it will fail. The IE7 will open a new window for one second and close it again, without asking for a download folder nor starting the download.
You have to mention one thing: It will work with the onclick-event, but not with any other event like onchange, onmouseout, onmouseover, ….
But a onclick-event at a select-element is not really realistic, the onclick would occurr also if you just click the dropdown-button when nothing is selected. Also manipulating the download-script will not work: Integrating a sleep(2)-call before the download starts is no resolution.
Cause
If you change the JavaScript-part of the html-file to
function go(jump){
var x = window.open(”");
x.document.location = jump;
}
you will get a hint: The IE will show up a notification automatic downloading was disabled due to security reaons.
And thats the cause: In default the option called “Automatic prompting for file downloads” is disabled. While this is the case IE7 won’t allow such initiated downloads - and there seems to be now way to by-pass this restriction. Or does anyone know a solution?