简体   繁体   English

ScriptX打印功能在IE8中不起作用

[英]ScriptX Print functionality is not working in IE8

I have a requirement of printing documents and I am using ScriptX for this purpose. 我需要打印文档,并且为此使用了ScriptX。 Everything works fine and prints the documents in IE11.But in IE8,I am getting an error,Error: The value of the property '$' is null or undefined, not a Function object. 一切正常,并且可以在IE11中打印文档。但是在IE8中,我收到一个错误消息,错误:属性“ $”的值为null或未定义,不是Function对象。

My printing code looks like this 我的打印代码如下所示

function PrintFunctionality(url, title,data)
{  

  if (!!navigator.userAgent.match(/Trident\/7\./)) {

        //alert('ie browser');
        var printWindow = window.open('', '', 'height=400,width=800');
        var htmltext = '<html><head><title>' + title + '</title>';
        htmltext += "<object id='factory' style='display:none' classid='clsid:1663ed61-23eb-11d2-b92f-008048fdd814' codebase='http://localhost/smsx.cab#Version=7,5,0,20'></object>";
        htmltext += "<script src='http://localhost/jquery-1.8.2.min.js'></script>";
        htmltext += "<script src='http://localhost/meadco-scriptx-1.0.2.js' type='text/javascript'></script>";
        htmltext += "<script type='text/javascript'>";
        htmltext += "$(function () {";
        htmltext += "if (MeadCo.ScriptX.Init()) {MeadCo.ScriptX.PrintPage(false);}});</script>";
        htmltext += '</head><body>';
        htmltext += data;
        htmltext += '</body></html>';
        printWindow.document.write(htmltext);
        printWindow.document.close();
        printWindow.focus();
        printWindow.print();
        printWindow.close();

        return false;
    }
};

and the installed version of script x in my system is: 我系统中脚本x的安装版本是:

The installed version of ScriptX is: 7.5.0.20 ScriptX的安装版本为:7.5.0.20

The installed version of Security Manager is: 7.5.0.20 安全管理器的安装版本为:7.5.0.20

The installed version of Print component is: 7.5.0.20 打印组件的安装版本为:7.5.0.20

Any thing to change in the code to work for IE8 ? 有什么需要更改代码才能适用于IE8的东西吗?

Background - there are a number of issues: 背景-存在许多问题:

  1. the printing functionality as shown will not run because IE 8 is Trident v4 如图所示的打印功能将无法运行,因为IE 8是Trident v4
  2. The code is assuming that the behaviour on document.close() is synchronous - it isn't. 该代码假定document.close()上的行为是同步的-并非如此。 Neither the loading of script files nor the initialisation of ScriptX is synchronous. 脚本文件的加载和ScriptX的初始化都不是同步的。 when printWindow.close() is called the browser is possibly still downloading stuff and/or running startup code and kills the window before it has a chance to start the print. 当调用printWindow.close()时,浏览器可能仍在下载内容和/或运行启动代码,并在有机会开始打印之前杀死窗口。 That is works with IE11 is because everything is in the cache and it is being used on a 'fast' machine. 之所以可以使用IE11,是因为所有内容都在缓存中,并且正在“快速”计算机上使用。
  3. jQuery does not initialise properly in this scenario (proof: remove all references to ScriptX and script leaving simply jQuery inclusion and $(function() {}}); -- it still errors even with jQuery 1.3 jQuery在这种情况下无法正确初始化(证明:删除对ScriptX和脚本的所有引用,仅保留jQuery包含和$(function(){}});-即使使用jQuery 1.3,它仍然会出错
  4. The code is trying to print the document twice - via MeadCo.ScriptX.PrintPage() and printWindow.print(). 该代码尝试两次通过MeadCo.ScriptX.PrintPage()和printWindow.print()打印文档。

In this scenario, jQuery and meaco-scriptx-1.0.2 offer no real benefit. 在这种情况下,jQuery和meaco-scriptx-1.0.2并没有真正的好处。

This is a temporary window that should be able to assume that ScriptX is already installed. 这是一个临时窗口,应该能够假定已经安装了ScriptX。 The answer/change to make it work in any version of IE is to go old-school: 使它在任何版本的IE中都可以使用的答案/更改是过时的:

function PrintFunctionality(url, title, data) {
    var printWindow = window.open('', '', 'height=400,width=800');
    var htmltext = '<html><head><title>' + title + '</title>';
    htmltext += "<object id='factory' style='display:none' classid='clsid:1663ed61-23eb-11d2-b92f-008048fdd814'></object>";
    htmltext += "<" + "script type='text/javascript'>";
    htmltext += "function printDocument() { window.setTimeout('window.close()',3000); factory.printing.print(false); }</" + "script>";
    htmltext += "</head><body onload='printDocument()'>";
    htmltext += data;
    htmltext += '</body></html>';
    printWindow.document.write(htmltext);
    printWindow.document.close();
    return false;            
}

Note that the window closes itself and it does after a delay that is deemed long enough for the print to have completed (spooled). 请注意,该窗口会自行关闭,并且会在被认为足以使打印完成(假脱机)的延迟后关闭。 It is a quirk of this scenario that you must call window.setTimeout() before calling factory.printing.print() or the timeout may not fire. 在这种情况下,您必须在调用factory.printing.print()之前先调用window.setTimeout(),否则可能不会触发超时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM