我的网页有以下javascript
function LoadPDF(filename)
{
var loc = filename;
document.getElementById("pdf").setAttribute("src", loc);
if (window.addEventListener) {
document.getElementById("pdf").addEventListener("load", LoadPrint, false);
}
else if (window.attachEvent) {
document.getElementById("pdf").attachEvent("onload", LoadPrint);
}
else {
document.getElementById("pdf").onload = LoadPrint;
}
}
function LoadPrint() {
alert('fired!');
if (document.getElementById("pdf").src !== "") {
var frm = document.getElementById("pdf");
frm.contentDocument.getElementById("pdf").contentWindow.print();
}
}
从后面的代码调用LoadPDF。 “pdf”是我的iframe。当pdf加载到iframe时,我想调用LoadPrint。但麻烦在IE 11中从未被称为。
有人可以帮忙吗?
答案 0 :(得分:1)
这是一个IE11 bug,MS拒绝修复,因为他们认为这是一个功能错误,他们不再修复旧浏览器版本的那种错误。
此错误的解决方法是将pdf文件加载到其他页面iframe中,然后在iframe中加载该页面。一个简单的带有文件参数的javascript pdf加载器:
<filename.html>?pdf=<pdf_file_to_load>
您可以将其与function LoadPDF(filename)
{
var loc = "pdf-loader.html?pdf="+filename;
document.getElementById("pdf").setAttribute("src", loc);
if (window.addEventListener) {
document.getElementById("pdf").addEventListener("load", LoadPrint, false);
}
else if (window.attachEvent) {
document.getElementById("pdf").attachEvent("onload", LoadPrint);
}
else {
document.getElementById("pdf").onload = LoadPrint;
}
}
function LoadPrint() {
alert('fired!');
}
LoadPDF('http://www.pdf995.com/samples/pdf.pdf');
一起使用。
然后您只需更改代码即可通过该加载程序加载pdf文件,如下所示:
LoadPrint
现在即使在IE11上,也会在iframe加载事件上调用load
函数。
这是我的工作示例,您甚至可以使用IE11进行测试:http://zikro.gr/dbg/html/ie11-iframe-pdf/
在这里,你可以看到一个10MB PDF加载的屏幕截图,只有在完成加载后它才会触发<div class="reseller_container">
<div class="reseller_header">BECOME A RESELLER</div>
<img src="https://cdn.shopify.com/s/files/1/1899/1203/files/jupa-reseller-background.png?12251079152443546141" />
<p>We're always on the lookout for <b>BUSINESSES OR INDIVIDUALS</b> who would like to <b>BUILD A RELATIONSHIP</b> with JUPA, whether that's <b>RESELLING</b> our charger or <b>ANYTHING ELSE</b>. If you feel this would be something for you then please <b>GET IN TOUCH</b> with us.</p>
**<a href="http://www.jupacharge.com/pages/contact"><img class="contact_button" src="https://cdn.shopify.com/s/files/1/1899/1203/files/jupa-get-in-touch.png?15833297944705309626" /></a>**
<div class="reseller_text">We will aim to respond to your enquiry within 1 business day</div>
</div>
<img class="deal_icon" src="https://cdn.shopify.com/s/files/1/1899/1203/files/jupa-deal.png?15833297944705309626" />
事件并提醒消息: