[英]How to check URLs of all tabs in all windows? (Google Chrome Extension)
我想檢查所有窗口中所有選項卡的URL,如果有一個匹配“ http://example.com/foo/bar.html ”的選項卡,我想重點關注該選項卡。 (如果沒有,我想在新選項卡中打開“ http://example.com/foo/bar.html ”。)
但是,我不知道如何檢查URL。
我怎樣才能做到這一點?
我不會全面概述實現,但是請看一下此條目:
http://developer.chrome.com/extensions/tabs.html#method-query
如您所見,它接受“ url”檢查。
如jshthornton所述,您可以使用chrome.tabs.query
方法:
chrome.tabs.query("http://example.com/foo/bar.html", function(tabs)
{
// if no tab found, open a new one
if (tabs.length == 0)
chrome.tabs.create({ url: "http://example.com/foo/bar.html" });
// otherwise, focus on the first one
else
chrome.tabs.update(tabs[0].id, { active: true });
});
請注意,如果第一個找到的選項卡不在當前活動窗口中,則此代碼不會將焦點放在該選項卡的窗口上。
您可以檢查以下鏈接以獲取更多詳細信息:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.