简体   繁体   English

如何从Firefox OS应用程序在浏览器中打开data:image / png; base64 URL?

[英]How to open a data:image/png;base64 URL in the browser from a Firefox OS app?

I need to open a data:image/png;base64 URL in the default browser in Firefox OS. 我需要在Firefox OS的默认浏览器中打开data:image / png; base64 URL。
The relevant portions of the code: 代码的相关部分:
HTML: HTML:

<img src="img/Link.png" onclick="generateLink()"/>
<a href="#" id="link" target="_blank">Link</a>

JS: JS:

document.getElementById("link").href=document.getElementsByTagName('canvas')[0].toDataURL();

The code works in Google Chrome. 该代码可在Google Chrome浏览器中使用。

In your JavaScript you have the expression: 在您的JavaScript中,您可以使用以下表达式:

document.getElementsByTagName('canvas')

but you don't have any canvas elements in your HTML code. 但您的HTML代码中没有任何canvas元素。

What you should be doing is using canvas' drawImage calls to place the bitmap into a canvas 2D context, then calling toDataURL on the canvas. 您应该做的是使用canvas的drawImage调用将位图放入画布2D上下文中,然后在画布上调用toDataURL。

Also, why does the user have to touch the image first to generate the link? 另外,为什么用户必须首先触摸图像才能生成链接? Why not create the data URL in one step? 为什么不一步一步创建数据URL?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM