如何解决使用chrome扩展程序构建从iframe检索的图像数组
这是交易:
我必须在工作中使用SaaS应用程序,并且打印解决方案太糟糕了。它使用Microsoft Windows客户端,该客户端使用websockets与chrome进行通信,而Thing的确令人生厌。...我只是将其扔掉,此刻正在使用自己的hack。
要打印的A4文档显示在iframe中。我将它们放在一个数组中,并在控制台中使用一些javascript在新选项卡中打开它们。看起来像这样:
// First,I get rid of the thousand errors per sec
// generated in the console by the websocket,eversince
// I deleted the Windows desktop client 'jsPrint'
WebSocket = undefined;
let iframe = document.getElementById('iframeID');
let images = iframe.contentDocument.querySelectorAll('.imgClass');
// I prepare the HTML for my A4 images
let imagesMarkUp = ``;
images.forEach(image => imagesMarkUp += `<img src="${image.src}">`);
// I insert the images inside a div and ship the whole thing
// to a new tab,also adding a script tag so that it can print automaticaly too.
window.open('').document.write(`
<head>
<title>Prints</title>
</head>
<body>
<div>${imagesMarkUp}</div>
</body>
<script>
window.setTimeout(window.print,300)
</script>
`);
整个过程还不错,但是我必须保持代码准备就绪,打开控制台,每次都复制粘贴,我认为对我和我的同事来说,创建chrome扩展名是个好主意。
理想的方法是单击扩展程序图标,这一切都将一move而就。
我还没有成功,而且我不太确定这是否可以完成...我尝试了使用背景脚本,各种权限,而且很显然,从扩展中查找iframe并不容易业务:/
你们中的任何一个人会提出一些建议吗? :)
我已经搜索了一阵子了,但没有成功:/
PS:我是菜鸟!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。