2016-08-24 74 views
0

我有以下代碼。當我點擊'打印地圖'按鈕然後彈出窗口打開,其中有兩個按鈕'保存'和'打印'。 當我點擊'保存'按鈕,它會打開窗口來保存文件。我可以直接使用保存按鈕在窗口功能

我想要的是當我點擊'打印地圖'按鈕然後單擊保存按鈕後窗口應該打開。

function PrintElem(elem) 
 
{ 
 
    Popup($(elem).html()); 
 
} 
 
function Popup(data) 
 
{ 
 
    var mywindow = window.open('', 'parent', 'height=400,width=600'); 
 
    mywindow.document.write('<html><head><title>my div</title>'); 
 
    /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />'); 
 
    mywindow.document.write('</head><body >'); 
 
    mywindow.document.write(data); 
 
    mywindow.document.write('</body></html>'); 
 
    mywindow.document.close(); // necessary for IE >= 10 
 
    mywindow.focus(); // necessary for IE >= 10 
 
    mywindow.print(); 
 
    mywindow.close(); 
 
    return true; 
 
}
<script src="http://cdnjs.cloudflare.com/ajax/libs/jspdf/0.9.0rc1/jspdf.min.js"></script> 
 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
 
<script src="http://html2canvas.hertzen.com/build/html2canvas.js"></script> 
 
<body> 
 
    <section> 
 
     <div class="main_div"> 
 
      <div> 
 
       <div class="nav_div"> 
 
        <input type="button" value="Print Map" onclick="PrintElem('.parent')" /> 
 
       </div>   
 
      </div> 
 
      <div class="parent">  
 
        <h1>Hello All</h1> 
 
      </div> 
 
     </div> 
 
    </section> 
 
</body> 
 
     

+0

你到目前爲止嘗試了什麼?我在這裏看到的唯一的東西是從http://stackoverflow.com/a/2255438/5703316 –

+0

複製/粘貼請閱讀我的問題...代碼是jst的演示..我不希望預覽窗口來點擊按鈕但要保存PDF – Roma

回答

0

會不只是添加了下載鏈接爲html您保存按鈕 - 真的不能看到這裏的保存按鈕 - 但如果你的目錄,它始終是相同的文件 - 您可以像這樣定位保存按鈕。

<a href="./directory/yourfile.pdf" download="newfilename">Save</a> 

這將節省與建議的名稱「newfilename」的文件,你也能發射,雖然,並且有使用的PDF格式的服務器名稱:

<a href="./directory/yourfile.pdf" download>Save</a> 

這是一個HTML5特性,以及在舊IE中不受支持,但它可能是一個建議。

希望它能解決你期待的目標,但我可能會誤解。

相關問題