ScriptX 打印功能在 IE8 中不起作用
ScriptX Print functionality is not working in IE8
我需要打印文档,我正在使用ScriptX来实现此目的。一切正常,并在IE11中打印文档。但是在IE8中,我收到一个错误,错误:属性'$'的值为空或未定义,而不是函数对象。
我的打印代码如下所示
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;
}
};
我的系统中安装的脚本 X 版本是:
已安装的 ScriptX 版本为:7.5.0.20
安全管理器的安装版本是:7.5.0.20
打印组件的安装版本为:7.5.0.20
在代码中更改任何内容以适用于IE8?
背景 - 有许多问题:
- 如图所示的打印功能将无法运行,因为IE 8是三叉戟v4
- 代码假设 document.close() 上的行为是同步的 - 事实并非如此。脚本文件的加载和 ScriptX 的初始化都不是同步的。当调用printWindow.close()时,浏览器可能仍在下载内容和/或运行启动代码,并在窗口有机会开始打印之前杀死窗口。这与IE11一起使用是因为所有内容都在缓存中,并且正在"快速"机器上使用。
- 在这种情况下,jQuery 无法正确初始化(证明:删除所有对 ScriptX 和脚本的引用,只留下 jQuery 包含和 $(function() {}});-- 即使使用 jQuery 1.3,它仍然出错
- 代码尝试打印文档两次 - 通过MeadCo.ScriptX.PrintPage()和printWindow.print()。
在这种情况下,jQuery 和 meaco-scriptx-1.0.2 没有提供真正的好处。
这是一个临时窗口,应该能够假定已安装 ScriptX。使其在任何版本的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;
}
请注意,窗口会自行关闭,并且在延迟后关闭,该延迟被认为足够长,以便打印完成(后台打印)。这种情况的一个怪癖是,您必须在调用 factory.printing.print() 之前调用 window.setTimeout(),否则超时可能不会触发。
相关文章:
- Recaptcha在IE7和IE8中不起作用
- 在IE8中不起作用的元素上触发单击事件
- 数据-在IE8中不起作用
- getComputedStyle替换:currentStyle(IE8/7)不起作用
- IE8 jquery ajax头请求不起作用
- 显示隐藏的html表在javascript(IE8)中不起作用
- ScriptX 打印功能在 IE8 中不起作用
- Angularjs 跨源资源共享 (CORS) 发布或放置方法在 IE8 和 IE9 中不起作用
- ExtJs 5.0:forEach on Array of Objects在IE8中不起作用
- 将JSON对象转换为敲除observable在IE8中不起作用,但在所有其他浏览器中都起作用
- 聚焦函数在ie8中不起作用
- 启动网格在IE8中不起作用
- Svg标签在IE8中不起作用
- Twitter引导程序示例在IE8中不起作用
- 引导程序3在IE8中不起作用(已检查其他答案)
- IE8的Javascript占位符不起作用
- Javascript中的开关案例在IE8中不起作用
- 如果我添加 pageX 页面 Y 在 IE8 中不起作用<!文档类型 html>.
- $.getScript 不起作用 (IE8)
- 点击事件不起作用IE8