jsPDF不工作在Chrome,只有Firefox 'Safari
jsPDF doesn't work in Chrome, only Firefox & Safari
我正在尝试使用jsPDF将应用程序导出为PDF。在浏览了网页后,在这里抓一行代码,在那里抓一段代码——我已经设法让它工作了……。
它适用于Firefox &
js文件使用(来自jsPDF)。也许过度。
<script type="text/javascript" src="PDF/standard_fonts_metrics.js"></script>
<script type="text/javascript" src="PDF/split_text_to_size.js"></script>
<script type="text/javascript" src="PDF/from_html.js"></script>
<script type="text/javascript" src="PDF/addhtml.js"></script>
<script type="text/javascript" src="PDF/addimage.js"></script>
我使用的代码是:
<script type="text/javascript">
function demoFromHTML() {
$('#listAreaPDF').css("display", "block");
var pdf = new jsPDF('p', 'pt', 'letter');
// source can be HTML-formatted string, or a reference
// to an actual DOM element from which the text will be scraped.
source = $('#listAreaPDF')[0];
pdf.setFontSize(24);
pdf.text(35, 40, "PDF Title here");
pdf.setFontSize(10);
pdf.text(500, 40, "Company Name AB");
// we support special element handlers. Register them with jQuery-style
// ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
// There is no support for any other type of selectors
// (class, of compound) at this time.
specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'#bypassme': function (element, renderer) {
// true = "handled elsewhere, bypass text extraction"
return true
}
};
margins = {
top: 80,
bottom: 60,
left: 40,
width: 522
};
// all coords and widths are in jsPDF instance's declared units
// 'inches' in this case
pdf.fromHTML(
source, // HTML string or DOM elem ref.
margins.left, // x coord
margins.top, {// y coord
'width': margins.width, // max width of content on PDF
'elementHandlers': specialElementHandlers
},
function (dispose) {
html2canvas($("#presentationArea"), {
onrendered: function (canvas) {
var imgData = canvas.toDataURL(
'image/png');
pdf.addImage(imgData, 'PNG', 20, 300);
pdf.save('Test.pdf');
}
});
// dispose: object with X, Y of the last line add to the PDF
// this allow the insertion of new lines after html
// pdf.save('Test.pdf');
},
margins
);
$('#listAreaPDF').css("display", "none");
}
</script>
在这里找到的代码的功劳。为了适应我的应用程序,我做了一些小的修改,我添加了一个到html2canvas的连接,将图像从应用程序中取出并放入PDF中。在Safari和Firefox中可以正常工作。
当点击并激活这个功能在Chrome我甚至没有收到一个空白的PDF,我什么也得不到。甚至没有弹出窗口或页面生成。
什么可能是原因Firefox&Safari工作,而不是Chrome?我还没试过ie浏览器,但我也不敢屏息以待。你知道有什么办法吗?我完全赞成。
谢谢您提供的任何帮助或建议。
这个问题可能与chrome不支持顶框导航有关。
Remove:内容初始化的顶部框架导航到数据url (removed)
https://www.chromestatus.com/feature/5669602927312896我们打算阻止网页加载数据:url在顶部框架使用标签,窗口。打开,窗口。位置和类似的机制。
伪url(如data:)通常会给用户带来困惑。由于不熟悉,这些方案被广泛用于欺骗和网络钓鱼攻击。理想情况下,用户在浏览网页时应该只使用两种众所周知的方案(http和https)。
在M58中已弃用
M60的去除
一个可能的解决方案是,如前面提到的google groups线程所述,使用iFrame
相关文章:
- onbeforeunload和asp:Safari和FireFox中的更新面板
- 在Firefox上使用聚合物的javascript依赖关系的HTML导入困难;Safari
- 元素意外地隐藏在Safari的某些实例中,总是出现在Firefox、Chrome中
- JS适用于Firefox和Safari,但不适用于Chrome.此处'是我的网站
- 有没有一种方法可以在过滤掉iOS Chrome、Firefox和其他浏览器的同时检测iOS safari
- 异步加载的SVG过滤器feColorMatrix在Chrome中工作,而不是在Safari或Firefox中
- JavaScript函数在Safari中有效,但在Firefox中找不到
- Chrome,Safari在从本地存储读取时挂起,而Firefox很好
- 支持 JavaScript 的检查例程适用于 Chrome/Opera/IE,但不适用于 Firefox/Safari
- RGB 到 HEX JavaScript 函数在 Chrome 中工作,但不能在 Firefox 或 Safari 中工
- window.onbeforeunload在IE8中不触发(在Firefox,Chrome和Safari中工作正常)
- window.dispatchEvent 在 Firefox、Safari 或 IE 中不起作用
- 是否可以在FireFox/Safari中创建多个WebSocket
- AngularJS日期过滤器firefox/safari问题
- 将SVG元素导出为SVG,PNG适用于chrome,但不适用于firefox/safari
- jsPDF不工作在Chrome,只有Firefox 'Safari
- 编码浏览器扩展,插件,Firefox, Safari, Chrome等…这是可能的吗?
- 简单的javascript jQuery代码在Chrome中工作,而不是Firefox, Safari, IE
- 使用firefox/safari/IE获取drop输入
- AngularJS ng-model在Firefox/Safari/Chrome中