Chrome 扩展 - 只是将当前页面保存到本地 html 文件中
我对 Chrome 扩展开发和网站技术(主要是 JS)都很陌生。
为了自学,我想创建一个 Chrome 扩展程序,可以将当前页面保存到桌面。我知道这只需通过“Ctrl+S”即可完成,但我想实现与 Chrome 扩展相同的功能。
如果可能的话,我想创建一个扩展,首先创建一个弹出菜单,其中顶行将是保存页面的按钮。
我试图自己解决这个问题,但是,我得到了下面的代码,该代码不起作用。您能给我一些如何继续的提示吗?
manifest.json
{
"name": "Extract",
"version": "2.0",
"description": "The first extension that I made.",
"browser_action": {
"default_icon": "icon.png",
"popup": "popup.html"
},
"permissions": [
"tabs"
]
}
popup.html
<style>
body {
min-width:357px;
overflow-x:hidden;
}
img {
margin:5px;
border:2px solid black;
vertical-align:middle;
width:75px;
height:75px;
}
</style>
<script>
function saveAsMe (filename)
{
document.execCommand('SaveAs',null,filename)
}
</script>
提前致谢!
I am new to both Chrome extension development and website techniques (mainly JS).
Trying to learn by myself, I wanted to create a Chrome extension that can save the current page, say, to desktop. I know this simply can be done by "Ctrl+S", but I want to implement the same thing as a Chrome extension.
If possible, I want to create an extension that first create a popup menu, in which the top row will be the button to save page.
I tried to figure it out by myself, however, I got the code below, which is not working. Could you please give me some hints on how to proceed?
manifest.json
{
"name": "Extract",
"version": "2.0",
"description": "The first extension that I made.",
"browser_action": {
"default_icon": "icon.png",
"popup": "popup.html"
},
"permissions": [
"tabs"
]
}
popup.html
<style>
body {
min-width:357px;
overflow-x:hidden;
}
img {
margin:5px;
border:2px solid black;
vertical-align:middle;
width:75px;
height:75px;
}
</style>
<script>
function saveAsMe (filename)
{
document.execCommand('SaveAs',null,filename)
}
</script>
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非使用 NPAPI 原生,否则无法使用 HTML5 或扩展将文件写入磁盘。您可以使用 FileSystem API 将其存储在 Chrome 文件系统中。 AFAIK,上次我使用它时它创建了一些您无法更改的 GGUID 文件。
有关这方面的更多信息,请访问有关探索文件系统 API 的 HTML5 教程
You cannot write files to disk using HTML5 or extensions unless you go native with NPAPI. There are FileSystem APIs that you can use to store it in the Chrome file system. AFAIK, last time I used it it created some GGUID file which you cannot change.
For more information regarding this, visit the HTML5 Tutorial regarding Exploring the FileSystem APIs