Solved

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

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
html input 8 43
Override MS CSS in SharePoint Online Modal Form 19 45
javascript - insert into js doc help 2 25
JavaScript Sort Ordering and Choice Limiting 5 25
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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 Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
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…

829 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