Solved

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

Posted on 2014-01-12
2
654 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

726 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