Register now and start sharing your code snippets.
-->

Opening a new tab with Firefox

JavaScript posted 7 months ago by christian

Note that this only works from a Firefox extension:

   1  function openTab(url, focus) 
   2    {
   3      var tab = getBrowser().addTab(url);
   4  
   5      if(focus)
   6      {
   7        getBrowser().selectedTab = tab;
   8      }
   9     
  10      return tab;
  11    }
  12  

Tagged open, tab, firefox

Opening a new window in the center of the screen with JavaScript

JavaScript posted 7 months ago by christian

This JavaScript code will open a URL in a new window and center the window on the screen, instead of showing the window in a random place:

   1  var url = 'http://google.com/';
   2  var width  = 640;
   3  var height = 480;
   4     
   5  var left   = (screen.width / 2) - (width / 2);
   6  var top    = (screen.height / 2) - (height / 2);
   7     
   8  var xWindow = window.open(url, 'post', 'resizable=1,width=' + width + ',height=' + height + ', top=' + top + ', left=' + left);
   9  
  10  xWindow.focus(); 

Tagged javascript, window, open, center, screen