English 中文(简体)
设置图像 Src 到本地文件。
原标题:Set Image Src to Local File

我正在编写一个Firefox扩展程序,希望用户能够使用本地图像更改网页上的图像。使用JavaScript可否更改图像源为用户计算机上保存的图像?

如果您需要更多信息,请告诉我。谢谢。

问题回答

你可以将图像的SRC设置为“file://” URI,或者任何其他字符串。但是获取路径可能会更加困难 - 你必须使用浏览器的内部机制来获取路径。

当然,从网页Javascript 来说这是完全不可能的,但是扩展程序的沙箱比页面弱得多,您可以对文件系统做很多事情,因此建议这是不可能的答案是明显错误的。

我认为这篇黑客文章对于最近的HTML5功能工作中支持访问本地文件有一些有用的信息。

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

我不确定直接使用本地文件作为图像,但最差的情况下,使用展示的技术,您可以创建一个数据URL来代替使用。

出于安全目的,JavaScript 无法访问本地文件系统。您的插件将不得不解决这个问题。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签