Reputation: 1439
How can I redirect the current tab when a button in a panel is clicked?
What I currently have in my code right now is the following :
Javascript
function doSearch (){
alert("Search!");
var tabs = require("tabs");
tabs.open("http://google.com");
}
XUL
<xul:panel>
<xul:hbox>
<button onclick="doSearch ()">Button 1</button>
</xul:hbox>
</xul:panel>
Upvotes: 0
Views: 353
Reputation: 37238
i would recommend this:
function doSearch (e){
var win = e.target.ownerDocument.defaultView;
win.alert("Search!");
win.top.document.location.href = "http://google.com";
}
document.YOURBUTTON.addEventListener('click', doSearch, false);
Upvotes: 0
Reputation: 5171
Assuming by "redirect" you mean "navigate to"... how about this?
function doSearch (){
var win = window.top.getBrowser();
var tab = win.selectedBrowser;
tab.contentWindow.location.href = "http://google.com";
}
That should be OK provided your XUL is an overlay to the ChromeWindow hosting the TabBrowser in question.
See MDN: Tabbed Browser for some other scenarios.
Upvotes: 1