CEWP 打印按钮,带有用于打印 SharePoint 表单的代码
CEWP Print Button with Code to print SharePoint form?
我目前有一个表单预览,它看起来完全符合我们希望它查找正在查看的列表项的方式,但问题是当我在 FOrm Display 中将我的打印按钮添加为 CEWP 时,它执行的功能与使用 Control P 完全相同并打印整个页面。请参阅代码。
<div style="text-align: center"><input onclick="window.print();return false;" type="button" value=" Print this page "/> </div>"
我想添加它,让它只打印表单,而不打印窗口中当前视图的其他内容,并实际填写 8.5 x 11。
有什么想法吗?
受此 InfoPath 打印按钮的启发,一种解决方案是获取 CEWP 的内容并创建一个仅包含这些内容的新窗口。
var patt = /**your CEWP ID here***/g;
var alldivs = document.getElementsByTagName('div');
var printpageHTML = '';
for(var i=0; i<alldivs.length; i++){
if(patt.test(alldivs[i].id)){
printpageHTML = '<HTML><HEAD>'n' +
document.getElementsByTagName('HEAD')[0].innerHTML +
'</HEAD>'n<BODY>'n' +
alldivs[i].innerHTML.replace('inline-block','block') +
''n</BODY></HTML>';
break;
}
}
var printWindow = window.open('','printWindow');
printWindow.document.open();
printWindow.document.write(printpageHTML);
printWindow.document.close();
printWindow.print();
printWindow.close();
修复:删除了 HTML 字符的转义。
简单的打印功能:
<input id="printpagebutton" type="button" value="Print this page" onclick="printpage()"/>
<script type="text/javascript">
function printpage() {
//Get the print button and put it into a variable
var printButton = document.getElementById("printpagebutton");
//Set the print button visibility to 'hidden'
printButton.style.visibility = 'hidden';
//Print the page content
window.print()
//Set the print button to 'visible' again
//[Delete this line if you want it to stay hidden after printing]
printButton.style.visibility = 'visible';
}
</script>
相关文章:
- 使用javascript将动态表从一个html页面打印到另一个html页
- 正在SharePoint 2013母版页中添加JQuery移动文件
- JavaScript打印功能使日历停止工作
- esri javascript异步打印
- 文本框不是从Javascript/Asp.net中的对话框中打印出来的
- jQuery/JavaScript在线公文包表单-打印样式表
- 如何打印嵌套对象的所有值
- 在终端中运行 JavaScript 时(使用 rhino),如何使用 print() 函数在一行中打印
- 打印预览没有应用程序页眉和页脚的html表格
- 正在打印图表上的文本
- Sharepoint JScript if语句未执行
- 如何使用Javascript客户端对象模型检索Sharepoint 2010列表项权限
- SharePoint 2010 Jquery/JSON Rest Multiple OR语句-如何
- Rhino打印功能
- 在通过child.print()打印之前,我如何等待图像加载到我的新窗口中
- 如何用javascript打印php数组
- Javascript,从静态函数中打印全局对象
- 在SharePoint中通过javascript打印
- CEWP 打印按钮,带有用于打印 SharePoint 表单的代码
- document.body.innerHTML嵌入SharePoint清除页面,如何打印结果和停止脚本