Javascript php如何打开另存为对话框?脚本自动下载

Javascript php如何打开另存为对话框?脚本自动下载,javascript,php,download,html2canvas,Javascript,Php,Download,Html2canvas,我有一个下载按钮,启动htmlcanvas,下载html并将其保存为png文件。我没有配置它,因为我不懂javascript。我已经玩了几个下载文件的教程,但我无法在单击时打开对话框,无论我尝试将图像下载到正在查看页面的任何设备的下载文件夹。我认为这是javascript的问题,而不是php的问题 <script type="text/javascript"> var $loading = $('#loader').hide(); $('#carddownload').on('cli

我有一个下载按钮,启动htmlcanvas,下载html并将其保存为png文件。我没有配置它,因为我不懂javascript。我已经玩了几个下载文件的教程,但我无法在单击时打开对话框,无论我尝试将图像下载到正在查看页面的任何设备的下载文件夹。我认为这是javascript的问题,而不是php的问题

<script type="text/javascript">
var $loading = $('#loader').hide();
$('#carddownload').on('click', function() {
showimage(); 
});
$(document)
.ajaxStart(function () {
$loading.show();
})
.ajaxStop(function () {
$loading.hide();
});
function showimage(){
html2canvas([document.getElementById('card')], {
onrendered: function(canvas)
{
var img = canvas.toDataURL()
$.post("save.php", {data: img}, function (file) {
window.location.href ="downloadpng.php?path="+ file}); 
}
});
}
</script>

<?php
$file = trim($_GET['path']);
// force user to download the image
if (file_exists($file)) {
    header('Content-Type: application/download');
    header('Content-Description: File Transfer');
    header('Content-Type: image/png');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    unlink($file);
    exit;
}
else {
    echo "error not found";
}

?>

var$loading=$('#loader').hide();
$('#carddownload')。在('单击',函数()上){
showimage();
});
$(文件)
.ajaxStart(函数(){
$loading.show();
})
.ajaxStop(功能(){
$loading.hide();
});
函数showimage(){
html2canvas([document.getElementById('card')){
onrendered:函数(画布)
{
var img=canvas.toDataURL()
$.post(“save.php”,{data:img},函数(文件){
window.location.href=“downloadpng.php?path=“+file});
}
});
}

如果您指的是“选择保存位置”对话框。这是浏览器和用户配置设置的一项功能,不能更改。()哇!那是浪费一个小时!在chrome和firefox中,它会自动保存,在IE中会打开一个窗口,因此,如果用户在默认情况下没有更改其设置,他们是否会看到“保存位置”对话框,而不管他们使用的是哪种浏览器?