0

I have this code to trigger a alert if some one blocks pop ups from my site:

var w = window.open( "url","_blank", "height = 200, width = 300, top=450, left=1025" );
if(w == null || typeof(w) == "undefined" || w.location.href == 'about:blank') {
   alert("Please enabled popups for this site to continue.");  
}

Problem is that the alert shows if i block or allow pop ups. Why does it keep getting triggered?

Many thanks

  • 2
    Not answering your question but: please avoid alerts.. if the user has already chosen NOT to have nasty annyoing popups, he surely doesn't want an nasty annoying alert as well.. show him an overlay instead if your website **depends** on opening a popup to work. If not, let this be the users decision. – Zim84 Aug 04 '13 at 21:51
  • have you tried logging the content of `w` or `w.location.href` at that point? – Dave Aug 04 '13 at 21:52
  • Zim84, it is to display website that we have currently done work on, it will display a random page in a new window so that they can say but as it is random, pop up blockers block it so i want to let visitors know that to view the other site they have to enable pop ups for my site. Its nothing evil and the link is displayed as "click here to open a site what we have done" –  Aug 04 '13 at 21:59
  • Dave. No, i have not logged anything. Just for some reason the alert triggers when blocked or when allowed –  Aug 04 '13 at 22:00
  • Maybe try checking if "w.closed" is true immediately after calling the ".open()" method – Ian Aug 04 '13 at 22:10
  • http://stackoverflow.com/questions/2914/how-can-i-detect-if-a-browser-is-blocking-a-popup – 3dgoo Aug 04 '13 at 22:17
  • Ian. How may i do this please? –  Aug 04 '13 at 22:18
  • 3dgoo, i have just implemented that code and it does not work. Someone else commented on that as well and they said id did not work for them either –  Aug 04 '13 at 22:26
  • @RichardEpton - That code does not work in Chrome. If you browse stackoverflow, or the related questions on that page, you can find this: http://stackoverflow.com/questions/668286/detect-blocked-popup-in-chrome?rq=1. – 3dgoo Aug 05 '13 at 00:35
  • Also, when replying to people in the comments, make sure to put the @ symbol before their name so that the person gets notified of the reply. – 3dgoo Aug 05 '13 at 00:37
  • Just follow stuff here: http://stackoverflow.com/questions/668286/detect-blocked-popup-in-chrome – Ian Aug 05 '13 at 13:29

1 Answers1

0

Instead of a pop up window I would recommend using a javascript modal pop up instead. Modal pop up windows will not be blocked and are not as intrusive as a pop up window.

Here is a demo:

There are many options for this. Here are a couple jquery options:

3dgoo
  • 15,716
  • 6
  • 46
  • 58
  • 3dgoo, No good to me sorry, i need it to open in a new window/tab as i have it now. i just need to know why the alert is being triggered when the site is not being blocked –  Aug 04 '13 at 22:10
  • @RichardEpton - Do you just want a link to open in a new window when someone clicks on a link? Or do you want a new window to pop up automatically when a page loads, without the user clicking on anything? – 3dgoo Aug 05 '13 at 00:39