「タブ」の編集履歴(バックアップ)一覧に戻る

タブ - (2014/10/30 (木) 08:45:00) の編集履歴(バックアップ)


タブを開く

var aTab = gBrowser.loadOneTab(url, {inBackground:false}); 

タブのブラウザオブジェクト (xul:browser) を取得

aTab.linkedBrowser;
gBrowser.getBrowserForTab(aTab); //中身は↑
基本。

タブのURLを取得

特定のタブ

aTab.linkedBrowser.currentURI.spec;
currentURI は nsIURI

カレントタブ

window.content.location.href;
window.content.document.URL;  ←タブにXULを読み込んでたりするとundefinedになる
gBrowser.currentURI.spec;
gBrowser.mCurrentBrowser.currentURI.spec;
mCurrentTab.linkedBrowser.currentURI.spec;
カレントタブに限定するとバリエーションが一気に広がる

タブのindexを取得

注意:もうちょっと調べてみるべき

特定のタブ

var index = tab._tPos;
あるいは、
var index;
var list = gBrowser.visibleTabs;
if (list.length > 1) {
    index = list.indexOf(tab);
} else {
    index = 0;
} 

カレントタブ

var index = gBrowser.tabContainer.selectedIndex;

特定のタブをアクティブにする

gBrowser.selectedTab = aTab;

コンテントエリアのchromeスクリプトが、それを表示してるタブを取得

var Ci = Components.interfaces;
var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
	.getInterface(Ci.nsIWebNavigation)
	.QueryInterface(Ci.nsIDocShellTreeItem)
	.rootTreeItem
	.QueryInterface(Ci.nsIInterfaceRequestor)
	.getInterface(Ci.nsIDOMWindow);
var selfTab = mainWindow.gBrowser._getTabForContentWindow(window);

タブがピン留めされてるかどうか

aTab.pinned; //true or false