来自打字稿/ JavaScript Web应用程序的书签页面

时间:2019-03-29 10:59:40

标签: javascript angular dom

我会将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吗?

1 个答案:

答案 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);