我有一个以pdf格式生成自定义生日模板的服务。 用户有信用点,当他点击按钮时,执行ajax调用以获取创建的pdf文件的编号,然后使用 window.location 将pdf显示给用户。
chrome和firefox的情况很好,但IE使用通用栏弹出窗口阻止pdf,并要求用户同意。当用户接受并单击“是”时,没有任何反应,用户需要再次单击该按钮才能使其生效,而在后端,用户的信用额已经计算在内。
该网站的用户群主要是老年人,我不能让这种情况发生,因为根据谷歌分析,60%的用户拥有IE浏览器。
这是电话:
$.ajax({
type: "POST",
url: "getNum.php",
dataType: "html",
data: {data: $.toJSON(birthday)},
success: function(data){
if (parseInt(data) <= 0){
$('#waitModal').modal('hide');
if(parseInt(data) != -10){
$('#signInModal').modal('show');
} else{
//no credit
}
}else{
window.location = "generateBirthdayCard.php?num="+parseInt(data)
}
}
这是显示pdf:
的脚本(generateBirthdayCard.php)if (!$_GET['num']) die("looking for ?url=http://www.....");
$num = trim(escapeshellarg($_GET['num']), "'");
//only if the requested refrence is an integer
if (is_numeric($num)){
$str = file_get_contents("/tmp/$num.pdf");
header('Content-Type: application/pdf');
header('Content-Length: '.strlen($str));
header('Content-Disposition: inline; filename="custom-birthday-cards.pdf"');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
ini_set('zlib.output_compression','0');
die($str);
}
编辑:当使用IE8的开发者工具模拟IE7时,在IE8和IE7中都会发生这种情况
答案 0 :(得分:0)
当您说“没有任何反应”时,您检查了浏览器缓存以获取新的pdf。我在下载文件之前遇到了IE的问题,但IE只是不打开它。
尝试使用fiddler来查看ajax方法是否确实正确地响应了pdf。
您可以在同一浏览器中打开其他PDF吗?例如this one