简体   繁体   English

将Image Src设置为本地文件

[英]Set Image Src to Local File

I am writing a Firefox extension and would like the users to be able to change an image on a web page with a local image. 我正在编写Firefox扩展,希望用户能够使用本地图像更改网页上的图像。 Is it possible, using JavaScript, to change the image source with an image that is saved on the user's local machine? 使用JavaScript,是否可以使用保存在用户本地计算机上的图像来更改图像源?

Let me know if you need more information. 如果您需要更多信息,请与我们联系。 Thanks 谢谢

You can set SRC of an image to a "file://" URI obviously, or any string for that matter. 您可以将图像的SRC显然设置为“ file://” URI,或任何与此相关的字符串。 But getting the path may prove more tricky - you'll have to use browser's internals to grab the path. 但是,获取路径可能会更加棘手-您必须使用浏览器的内部组件来获取路径。

Of course this is completely impossible from a webpage javascript, but an extension is in a much weaker sandbox than a page, and you can do quite a bit about the filesystem, so answers that suggest it's impossible are plain wrong. 当然,使用网页javascript完全不可能做到这一点,但是扩展名远比页面弱得多,而且您可以对文件系统做很多工作,因此提示不可能的答案是完全错误的。

I think this hacks post has some useful information on recent HTML5 feature work to support access to local files: 我认为这篇hack帖子提供了有关最近的HTML5功能工作的一些有用信息,以支持对本地文件的访问:

http://hacks.mozilla.org/2010/02/an-html5-offline-image-editor-and-uploader-application/ http://hacks.mozilla.org/2010/02/an-html5-offline-image-editor-and-uploader-application/

I'm not sure about using local files as images directly, but at worst, using the techniques demonstrated there, you could create a data: URL to use instead. 我不确定直接将本地文件用作图像,但是最糟糕的是,使用此处演示的技术,您可以创建一个data:URL来代替。

JavaScript cannot access the local filesystem for security purposes. 为了安全起见,JavaScript无法访问本地文件系统。 Your plug-in will have to work-around this problem. 您的插件将必须解决此问题。

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

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