douzhanglun4482 2013-09-26 07:44
浏览 404

将Content-Disposition标头配置为附件时,不会触发iframe的load事件

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c程序不知道为什么得不到结果
    • ¥40 复杂的限制性的商函数处理
    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置