Chrome扩展程序 - 仅用于将当前页面保存到本地HTML文件中 [英] Chrome extension - just to save current page into local html file

查看:102
本文介绍了Chrome扩展程序 - 仅用于将当前页面保存到本地HTML文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Chrome扩展程序开发和网站技术(主要是JS)都很陌生。



试图自己学习,我想创建一个可以保存的Chrome扩展程序当前页面,比如桌面。我知道这可以通过Ctrl + S完成,但我想实现与Chrome扩展相同的功能。



如果可能,我想创建一个首先创建一个弹出式菜单的扩展,其中最上面一行将是保存页面的按钮。



我试图自己弄清楚,但是,我得到了下面的代码,这是行不通的。您可以给我一些关于如何进行的提示吗?

manifest.json



< pre $ {
name:Extract,
version:2.0,
description: ,
browser_action:{
default_icon:icon.png,
popup:popup.html
},
permissions:[
标签
]
}

popup.html

 < style> 
body {
min-width:357px;
overflow-x:hidden;
}

img {
margin:5px;
border:2px纯黑色;
vertical-align:middle;
width:75px;
height:75px;
}
< / style>

< script>
函数saveAsMe(文件名)
{
document.execCommand('SaveAs',null,filename)
}
< / script>

提前致谢!

解决方案

除非使用NPAPI本机,否则无法使用HTML5或扩展将文件写入磁盘。有FileSystem API可用于将其存储在Chrome文件系统中。 AFAIK,上一次我使用它创建了一些你不能改变的GGUID文件。



有关这方面的更多信息,请访问关于探索FileSystem API


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!

解决方案

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

这篇关于Chrome扩展程序 - 仅用于将当前页面保存到本地HTML文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆