We are all aware of what Pop Ups are and how much fun it is to close them. In this article we will see how to write a small application that detect Pop Up Blockers. This is done by using simple JavaScript. Please note that for this code to work you must have some Pop Up blocker installed on your PC.
We are all aware of what Pop Ups are and how much fun it is to close them. In this article we will see how to write a small application that detect Pop Up Blockers. This is done by using simple JavaScript. Please note that for this code to work you must have some Pop Up blocker installed on your PC.
Why detecting Pop Up Blockers?
Sometimes in an application you need to make a Pop Up window and display data in it. If the user has Pop Up Blocker enabled than the window will never open and he will never see the required data. For this reason you can run a Pop Up blocker test which will determine that if the user has enabled Pop Ups on his machine or not.
Making a DetectPopUp Function:
First thing that we will do is to call the DetectPopUp function on the page load. This can be done by using the onload event of the body tag.
<body onload="DetectPopUp();"> |
Now let's see the complete implementation of the Pop Up detecting script. DetectPopUp is the main function which determines the presence of the Pop Up blocker. If the variable popup is null than it means Pop Up Blocker is ON else its OFF. The function PrintMessage is simple used to print the messages on the form.
function DetectPopUp() { var popup = window.open('blank.htm','Testing','width=300,height=300'); if(popup != null) { // This means that popup blocker is OFF PrintMessage('PopUp Blocker is OFF','green'); } else { // This means that popup blocker is on PrintMessage('PopUp Blocker is ON','red'); } } function PrintMessage(message,color) { document.getElementById('MyLabel').style.color = color; document.getElementById('MyLabel').style.fontWeight = 'bold'; document.getElementById('MyLabel').innerHTML = message; } |
This is pretty much all you need to do. I hope you liked the article, happy coding!