Skip to content

Instantly share code, notes, and snippets.

@hongaar
Created July 9, 2015 12:10
Show Gist options
  • Save hongaar/9edf10e99834615a6ae0 to your computer and use it in GitHub Desktop.
Save hongaar/9edf10e99834615a6ae0 to your computer and use it in GitHub Desktop.
Browser Tab Switcher script
<a href="admin" target="admin" class="tabswitcher">admin section</a>
<a href="./" target="site" class="tabswitcher">view site</a>
tabswitcher = function()
{
var popup;
var opener;
var onClick = function(e)
{
var target = opener || popup || false;
var href, windowName;
if (target)
{
href = target.location.href.replace('#', '') + '#';
$(this).attr('href', href);
}
else
{
href = $(this).attr('href');
windowName = $(this).attr('target');
popup = window.open('', windowName);
if (popup.location.href == 'about:blank')
{
popup.location.href = href;
}
e.preventDefault();
}
};
return
{
init: function()
{
opener = window.opener || false;
$('a.tabswitcher').on('click', onClick);
}
};
}();
$(document).ready(function() {
tabswitcher.init();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment