我会将Angular应用程序中的页面添加到收藏夹。
我在此网站上找到了一个代码
const title = document.title;
const url = document.location;
if (window.sidebar) { // Firefox
window.sidebar.markup(title, url, '');
} else if (window.opera && window.print) { // Opera
var elem = document.createElement('a');
elem.setAttribute('href', url);
elem.setAttribute('title', title);
elem.setAttribute('rel', 'sidebar');
elem.click(); //this.title=document.title;
} else if (document.all) { // ie
window.external.AddFavorite(url, title);
}
此代码为obsolete,因为出现错误
Property 'sidebar' does not exist on type 'Window'
我想知道如何使此代码专门用于FF和chrome吗?
答案 0 :(得分:0)
请查看以下内容:https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/bookmarks/create
function onCreated(node) {
console.log(node);
}
var createBookmark = browser.bookmarks.create({
title: "bookmarks.create() on MDN",
url: "https://developer.mozilla.org/Add-ons/WebExtensions/API/bookmarks/create"
});
createBookmark.then(onCreated);