其實自從用了 Evernote 後,
就很少有需要將整個網頁存起來的需求了,
不過 mht 還是有它的方便性在, Chrome 也有提供簡單的方式來下載
manifest.json
{
"manifest_version": 2,
"name": "ironman6",
"version": "1.0",
"browser_action": {
"default_title": "Day 17"
},
"background": {
"scripts": ["background.js"],
"persistent": false
},
"permissions": [
"pageCapture"
]
}
background.js
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.pageCapture.saveAsMHTML({tabId: tab.id}, function (mhtml){
var url = window.URL.createObjectURL(mhtml);
var title = tab.title;
download(url, title + '.mhtml');
});
});
function download(url, fileName){
var a = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
a.href = url;
a.download = fileName;
var e = document.createEvent('MouseEvents');
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
a.dispatchEvent(e);
}
雖然 mht 可以直接拖拉到 Chrome 檢視,
但卻不能在 iframe 裡面使用,
之前想做相關應用時感覺很不方便.