本文介绍了不允许将顶部框架导航到数据URL:JsPDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
try {
var a;
var b = new jsPDF("p", "pt", "a3");
var c = document.getElementById("leftPieCanvas").toDataURL("image/png");
b.addImage(c, "PNG", 265, 60);
a = document.getElementById("rightPieCanvas").toDataURL("image/png");
b.addImage(a, "PNG", 205, 440);
if ($("#sales_table").length) {
var d = tableToJson($("#sales_table").get(0));
b.setFont("helvetica");
b.setFontType("bold");
b.setFontSize(9);
$.each(d, function(a, c) {
$.each(c, function(c, d) {
b.cell(40, 830, 55, 20, d, a);
});
});
}
b.output("dataurlnewwindow");
} catch (e) {
alert(e);
}
以上代码在firefox中工作,但不在chrome中,我用Google搜索并获得建议使用iframe所以我创建了iframe但无法将此代码放在上面的代码中,任何人都可以建议我如何将以下代码添加到上面的代码中,这样我也可以在Google Chrome中渲染PDF。
Above code is working in firefox but not in chrome, i googled and got suggestions that use iframe so i have created iframe but unable to put this code in above code, anyone can suggest please that how do i add the below code into above code so i can render a PDF in google chrome also.
var html = '<html>' +
'<style>html, body { padding: 0; margin: 0; } iframe { width: 100%; height: 100%; border: 0;} </style>' +
'<body>' +
'<iframe src="' + url + '"></iframe>' +
'</body></html>';
推荐答案
try {
var a;
var b = new jsPDF("p", "pt", "a3");
var c = document.getElementById("leftPieCanvas").toDataURL("image/png");
b.addImage(c, "PNG", 265, 60);
a = document.getElementById("rightPieCanvas").toDataURL("image/png");
b.addImage(a, "PNG", 205, 440);
if ($("#sales_table").length) {
var d = tableToJson($("#sales_table").get(0));
b.setFont("helvetica");
b.setFontType("bold");
b.setFontSize(9);
$.each(d, function(a, c) {
$.each(c, function(c, d) {
b.cell(40, 830, 55, 20, d, a);
});
});
}
//b.output('dataurlnewwindow');
var uri = b.output('dataurlstring');
openDataUriWindow(uri);
} catch (e) {
alert(e);
}
function openDataUriWindow(url) {
var html = '<html>' +
'<style>html, body { padding: 0; margin: 0; } iframe { width: 100%; height: 100%; border: 0;} </style>' +
'<body>' +
'<iframe src="' + url + '"></iframe>' +
'</body></html>';
a = window.open();
a.document.write(html);
}
这篇关于不允许将顶部框架导航到数据URL:JsPDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!