2012-06-25 49 views
0

我有一個配方的博客,並有從博客文章僅打印配方的選擇,這是所有設置和偉大工程,正確的東西被印刷等使用此javascript:如何將非變量文本添加到JavaScript打印彈出?

<script type='text/javascript'> 

// Print recipe using iframe 
function printRecipe(){ 
var content = document.getElementById(&quot;recipe&quot;); 
var pri = document.getElementById(&quot;ifmcontentstoprint&quot;).contentWindow; 
pri.document.open(); 
pri.document.write(content.innerHTML); 
pri.document.close(); 
pri.focus(); 
pri.print(); 
} 

我想要做的是在每個「打印食譜」的底部添加一個頁腳,其中包含網站地址。這將從配方到配方不變,但我不希望它顯示在原始配方上,因此只有在打印配方時才需要顯示它。所以我知道我必須在代碼中添加它,但到目前爲止沒有運氣。

我試圖搜索論壇的負載,沒有真正的答案是什麼必須是一個簡單的問題..

請幫助! 謝謝。

+0

+1取消-1,不知道爲什麼這個問題是downvoted 。 –

回答

1

這一行後:

pri.document.write(content.innerHTML); 

添加您的頁腳:

pri.document.write("My custom footer! Can include HTML"); 

最終代碼:

<script type='text/javascript'> 

// Print recipe using iframe 
function printRecipe(){ 
var content = document.getElementById("recipe"); 
var pri = document.getElementById("ifmcontentstoprint").contentWindow; 
pri.document.open(); 
pri.document.write(content.innerHTML); 
pri.document.write("My custom footer! Can include HTML"); 
pri.document.close(); 
pri.focus(); 
pri.print(); 
} 
</script> 
+0

+1。注意(對於OP)「可以包含HTML」也意味着可以應用適當的樣式。 – nnnnnn

+1

非常感謝!我問過這麼多人,直到現在還沒有人給我答案!有用! :-) –

+0

至少現在你知道去哪裏尋求幫助! :) –

相關問題