0
我想在這個「popup.js」中添加CurrentTabs的任何URL到書籤。如何將URL添加到書籤?
function GetUrls()
{
var CurrentTabs = new Array();
chrome.tabs.query({}, function (tabs) {
for (var i = 0; i < tabs.length; i++)
{
CurrentTabs[i] = tabs[i];
}
for (var i = 0; i < CurrentTabs.length; i++)
{
document.write("<b>" + CurrentTabs[i].title+"</b>"+"<br/><a href='" + CurrentTabs[i].url + "' target='_blank'>" + CurrentTabs[i].url + "</a><br/><br/>");
}
});
}
window.addEventListener("DOMContentLoaded", GetUrls());
document.getElementById("addBookmark").addEventListener('click',addGoogleBookmark);
function addGoogleBookmark()
{
chrome.bookmarks.create({title:"Extension bookmarks",parentId:?????,url:"http://www.google.com"});
alert("Added to bookmarks");
}
問題在這裏函數addGoogleBookmark()什麼是parentId? 有什麼想法?
這是popup.html:
<!DOCTYPE html>
<html>
<head>
<title>Links Collector</title>
<script src="popup.js"></script>
</head>
<body>
<input id="addBookmark" type="button" value="Add a Google bookmark"></input>
<style>
body {
width:500px;
height: 300px;
}
</style>
</body>
</html>
當我寫的任何字符串,出現錯誤沒有定義。 – Gemy
可選意味着你可以完全擺脫這個'chrome.bookmarks.create({title:「擴展書籤」,url:「http://www.google.com」})''的參數。 – guillaumekln