Skip to content

Instantly share code, notes, and snippets.

@loopdream
Last active October 29, 2018 11:15
Show Gist options
  • Save loopdream/65c842dd96450751dd3c to your computer and use it in GitHub Desktop.
Save loopdream/65c842dd96450751dd3c to your computer and use it in GitHub Desktop.
Open link in new tab - checks for popup blocker
openInNewTab = function(url) {
var popupBlockerChecker = {
check: function(popup_window){
var _scope = this;
if (popup_window) {
if(/chrome/.test(navigator.userAgent.toLowerCase())){
setTimeout(function () {
_scope._is_popup_blocked(_scope, popup_window);
},200);
}else{
popup_window.onload = function () {
_scope._is_popup_blocked(_scope, popup_window);
};
}
}else{
_scope._displayError();
}
},
_is_popup_blocked: function(scope, popup_window){
if ((popup_window.innerHeight > 0)==false){ scope._displayError(); }
},
_displayError: function(){
alert("Popup Blocker is enabled! Please add this site to your exception list.");
}
};
var popup = window.open(url, '_blank');
popupBlockerChecker.check(popup);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment