Question

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>
Was it helpful?

Solution

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.

OTHER TIPS

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top