Created
July 9, 2015 12:10
-
-
Save hongaar/9edf10e99834615a6ae0 to your computer and use it in GitHub Desktop.
Browser Tab Switcher script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href="admin" target="admin" class="tabswitcher">admin section</a> | |
<a href="./" target="site" class="tabswitcher">view site</a> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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