js如何去除打印时候浏览器自带的页头页尾的信息

版权声明:转载请注明转载地址 http://blog.csdn.net/qq_30938097 https://blog.csdn.net/qq_30938097/article/details/79159003




function printpr()   //预览函数
	{
		//document.all("qingkongyema").click();//打印之前去掉页眉,页脚
		
		var OLECMDID = 7;
		var PROMPT = 1; 
		//var WebBrowser1 = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
		//document.body.insertAdjacentHTML('beforeEnd', WebBrowser1); 
		remove_ie_header_and_footer();
		WebBrowser1.ExecWB(OLECMDID, PROMPT);
		WebBrowser1.outerHTML = "";

	}	

function remove_ie_header_and_footer() {
  var hkey_path;
  hkey_path = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
  try {
   var RegWsh = new ActiveXObject("WScript.Shell");
   RegWsh.RegWrite(hkey_path + "header", "");
   RegWsh.RegWrite(hkey_path + "footer", "");
  } catch (e) {
  }
 }	

在页面还需要加上 

 <OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>

这个object 每次最好打印重新创建 用js,要不然会出现错误问题

没有更多推荐了,返回首页