views:

1100

answers:

2

I am trying to change the url of a currently open tab in javascript firefox extension

Any pointers please?

+2  A: 

I believe it's "gbrowser.loadURI()". Try reading this page on MDC about interacting with the global variable gBrowser, and here about the loadURI method.

TML
A: 

The mozilla doc mentioned by TML has sample code for this under "Reusing by other criteria", but it's broken. The corresponding talk page says to add this line to fix it:

tabbrowser.loadURI(url, tabbrowser.currentURI, "UTF-8");

However, if you've already got the tab object (say from calling addTab earlier) then I think it's simpler to do:

gBrowser.selectedTab = mytab;
gBrowser.loadURI(myurl);

I don't see any way to change the URL of a tab which is NOT selected, but that would be nice - I hate stealing focus.

UPDATE: here's how you do it w/o selecting the tab. Simple:

gBrowser.getBrowserForTab(mytab).loadURI(myurl);
Ian Wilkes