简体   繁体   中英

change url of tab javascript firefox extension

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

Any pointers please?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM