简体   繁体   中英

Get a local file from plugin to javascript

I have developped a brower plugin that Acquire a picture from a Scanner or a Camera and save the picture in the file system of the user. The output is the filepath to the picture. I want to preview the picture in the Broswer, using javascript...

How can I get the picture without user interaction ?

( part of a Web App only compatible with Google Chrome)

如果你已经拥有了图像的内容,你可以直接加载它们,通过base64编码并提供如下URL:

<img src="data:image/png;base64,iVBORw0KGgoAAAANS..." />

If you have the filepath returned by your browser plugin and you have identified the event when you have to display the image then you can call ShowImage(filepath) function on that event.

<script type="text/javascript">
    function ShowImage(filePath) {
        $("#preview").append("<img alt='img' src='" + filePath + "'");
    }
</script>

Your HTML should contain the div:

<div id="preview"></div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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