如何将非可变文本添加到javascript打印弹出窗口中
How to add non-variable text into javascript print popup?
我有一个食谱博客,有一个选项可以只打印博客文章中的食谱,这一切都设置好了并且效果很好,使用此javascript打印正确的东西等:
<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.close();
pri.focus();
pri.print();
}
我想做的是在每个"打印食谱"的底部添加一个带有网站地址的页脚。这将因食谱而异,但我不希望它显示在原始食谱上,因此它只需要在打印配方时才显示。所以我知道我必须在此代码中的某个地方添加它,但到目前为止还没有运气。
我试图搜索大量论坛,但对必须是一个简单问题没有真正的答案。
请帮忙!谢谢。
在此行之后:
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>
相关文章:
- 打印javascript控制台的堆栈跟踪
- php:打印javascript/jquery dom就绪
- 如何在html元素中打印javascript变量
- 在htm-php页面中打印Javascript函数
- 使用请求对象中可用的值打印 JavaScript 警报
- 如何使用PHP打印JavaScript
- 如何在我的视图中打印JavaScript代码
- 在自定义控制台中打印javascript错误
- 使用POS打印机打印Javascript收据
- 在移动设备(ios)上打印Javascript
- 如果会话中的属性不为 null 或默认值,则运行/打印 JavaScript Razor ASP.NET MVC
- 在 PHP 中打印 JavaScript 代码不起作用
- 在 php 中打印 javascript 的值
- 打印 Javascript 而不是 ASP(经典)输出
- 如何在 HTML 中打印 javascript 函数的返回值 “添加 {x} +{y}={result}”
- 在 PHP 中打印 JavaScript 代码
- WebClientPrint 用于 Chrome 上的客户端打印 javascript 问题
- 如何打印 JavaScript 非对象的所有函数
- PHP 字符串包含打印 Javascript 时的换行符问题
- 在 Javascript 中打印 Javascript