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 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测