Solved

How to identify whether the pop up windows are blocked in the browser through javascript?

Posted on 2014-01-12
2
652 Views
Last Modified: 2014-01-13
Hi,

How to identify whether the pop up windows are blocked in the browser through javascript?
Is there any javascript available to identify?

I just need to provide alert to user to enable pop up in case if it is blocked
0
Comment
Question by:Rocking
2 Comments
 
LVL 58

Assisted Solution

by:Gary
Gary earned 250 total points
ID: 39775037
You need to open a popup and check for its existence

var mypopup= window.open('/mypopup.php', 'mypopupname');
if (mypopup== null || typeof(mypopup)=='undefined') { 	
	alert('Please disable your pop-up blocker'); 
} 

Open in new window

Of course you could do a quick open and close (if it exists) e.g.
var mypopup= window.open('/mypopup.php', 'mypopupname');
if (mypopup== null || typeof(mypopup)=='undefined') { 	
	alert('Please disable your pop-up blocker'); 
}
else{
	mypopup.close()
}

Open in new window

0
 
LVL 18

Accepted Solution

by:
Matthew Kelly earned 250 total points
ID: 39775042
So a simple way is to change the part of the code that would execute the pop up, put it into a variable and check to see if it is null or undefined. Note that this method doesn't work if you want to try to detect if they have pop up blocking on prior to a click that would open the pop up. This is because every browser is different and pop up blocking is a browser setting,  not an html setting.

<script type="text/javascript">
function buttonClicked() {
  var targetWin= window.open("popup.php");

  if(targetWin==null || typeof(targetWin)=='undefined')
  { 
    alert('Pop ups are required for parts of this application to work. Please Turn off your Pop Up blocker');
  }
}
</script>

<input type="button" onclick="buttonClicked();" value="Click For Pop Up" />

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question