First of all i just want the 'load' event to be fired only in Mozilla Firefox.
I've already tried different ways, but all i came to know is that load event of an ifrmae will only gets fired while the 'Content-Disposition' header is configured as 'inline'.
Is there any other event by which i came to know that the iframe dialog box pops up and ask user to save the file?
Please have look into the following implementation of mine and help me to get the proper solution.
HTML code :
<html>
<head>
<script type="text/javascript" src="FileName.js"></script>
</head>
<body>
<input type = "button" value="Download" onclick = "javascript:downloadFile('http://localhost/data.php');"></input>
</body>
</html>
Javascript code :
var downloadFile = function(url) {
// create hidden iframe
var id = "xyz";
var frame = document.createElement('iframe');
frame.id = id;
frame.name = id;
frame.style="visibility:hidden;display:none";
document.body.appendChild(frame);
var callback = function() {
alert('completed');
};
frame.onload = callback;
frame.src = url;
};
PHP code :
// Set Content Disposition header
header('Content-Disposition: attachment; filename=some.txt');
// Set content type header
header('Content-Type: application/octet-stream');
$file = "some.txt";
if(!file_exists($file)) die("I'm sorry, the file doesn't seem to exist.");
header('Pragma: no-cache');
header('Expires: 0');
readfile($file);
?>
Thanking you in advance. Hoping for a proper solution.