Chrome extension - just to save current page into local html file

时光总嘲笑我的痴心妄想 提交于 2020-01-05 04:37:11

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/7539647/chrome-extension-just-to-save-current-page-into-local-html-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!