Solved

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

Posted on 2014-01-12
2
647 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
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…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now