Popup Blocker Detection 2

Submitted by:J Kamy81

Date added:26 November, 2018

Category:JavaScript

Cross-browser method for testing for pop-up blockers.

Tags: popup , blocker

Code Snippet:

function detectPopupBlocker() {
var test = window.open(null,"","width=100,height=100″);
try {
test.close();
alert(“Pop-ups not blocked.");
} catch (e) {
alert(“Pop-ups blocked.");
}
}

// Created by: Simon Willison
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != ‘function’) {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}

addLoadEvent(detectPopupBlocker);
 
 

Comments