如何打印而不显示java脚本中的打印dailog框 [英] how to print without showing print dailog box in java script

查看:82
本文介绍了如何打印而不显示java脚本中的打印dailog框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if (navigator.appName == "Netscape") {
             var PrintCommand = '< OBJECT ID="PrintCommandObject" WIDTH=0 HEIGHT=0 ';
PrintCommand += 'CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
     document.body.insertAdjacentHTML('beforeEnd', PrintCommand);
     PrintCommandObject.ExecWB(6, -1); PrintCommandObject.outerHTML = "";
        }
        else { window.print(); }





显示此错误:JavaScript运行时错误:无法获取未定义或空引用的属性insertAdjacentHTML。我正在使用IE浏览器。

我怎么能得到这个请帮助我。



It is showing this error:JavaScript runtime error: Unable to get property 'insertAdjacentHTML' of undefined or null reference. I am using IE browser.
how can i get this please help me.

推荐答案

MSDN:insertAdjacentHTML方法 [ ^ ]:文档中的备注部分说:

MSDN: insertAdjacentHTML method[^]: Remarks section in the document says:
You cannot insert text while the document is loading. Wait for the onload event to fire before attempting to call this method.

When using the insertAdjacentHTML method to insert script, you must include the DEFER attribute in the script element.





很可能你的文档没有完全加载。如果你正在使用jQuery,有一个非常方便的方法 document.ready() [ ^ ]只会在您的文档后调用已经完全装满了。您可以将代码放在此方法中。如果您不确定,请在调用此代码之前确保您的文档已完全加载。



希望有所帮助!



Quite possibly your document has not completely loaded. If you are using jQuery there is a very handy method document.ready()[^] which will be called only after your document has completely loaded. You can put your code inside this method. If you are not sure, make sure your document has completely loaded before this code is called.

Hope that helps!


这篇关于如何打印而不显示java脚本中的打印dailog框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆