使用Javascript在横向模式下打印Sharepoint Web部件

时间:2019-02-14 09:08:37

标签: javascript printing sharepoint-2013

我有共享点列表,需要在其中添加打印按钮到项目。 我已经使用了脚本编辑器和以下代码:

<script type="text/javascript">
function imgChange2( img ) { document.printbutton.src = img; } </script><img name="printbutton" id="printbutton" onmouseover="imgChange2(&#39;/collab/generic1/Aaams/Lists/CarouselPictures/print_o.png&#39;)" onmouseout="imgChange2(&#39;/collab/generic1/Aaams/Lists/CarouselPictures/print_w1.png&#39;)" onclick="javascript:void(PrintWebPart()); " src="/collab/generic1/Aaams/Lists/CarouselPictures/print_w1.png" alt=""/>  
<script language="JavaScript">

var WebPartElementId = 'MSOZoneCell_WebPartWPQ2';
function PrintWebPart()
{
var bolWebPartFound = false;
if (document.getElementById != null)
{
var PrintingHTML = '<HTML>\n<HEAD>\n';
if (document.getElementsByTagName != null)
{
var HeadData= document.getElementsByTagName("HEAD");
if (HeadData.length > 0)
PrintingHTML += HeadData[0].innerHTML;
}
PrintingHTML += '\n</HEAD>\n<BODY>\n';
var WebPartData = document.getElementById(WebPartElementId).style.display(“landscape”);
if (WebPartData != null)
{
PrintingHTML += WebPartData.innerHTML;
bolWebPartFound = true;
}
else
{
bolWebPartFound = false;
alert ('Cannot Find Web Part');
}
}
PrintingHTML += '\n</BODY>\n</HTML>';

if (bolWebPartFound)
{
var PrintingWindow = window.open("","PrintWebPart", "toolbar,width=800,height=600,scrollbars,resizable,menubar"); 
PrintingWindow.document.open();
PrintingWindow.document.write(PrintingHTML);
PrintingWindow.document.close();
PrintingWindow.focus();
PrintingWindow.print();
PrintingWindow.close();

}
}</script>  

它可以工作,但是它只能在纵向模式下工作,并且用户每次都必须将模式更改为横向。是否可以使用代码更改模式? 您能帮我解决这个问题吗?

0 个答案:

没有答案