开发者

Legally avoiding popup blocking

What is causing some browsers to see my code as unsolicited?

I have a web site devoted to helping people with interactive sessions. It starts with the user clicking [Begin] so this is a consented action. This should (1) open a popup while (2) redirecting the first page to a end page as below :

<head>  
<SCRIPT language="JavaScript">
      function openwindow(){window.open("{INTERACTION}","interaction","resizable=0,width=800,height=600,status=0");}</SCRIPT>
</head>   
<body>
<FORM action="end.php" method="{METHOD}" >  
<input type="submit"  class="button" 
       onClick="javascript: openwindow()" 
       value="Begin" />
</FORM>
</body>

As said, this is not trying to open an unrequested popup but some strains of IE and Ch开发者_如何学Crome appear to be treating it as such. I have been trying to get a fix, most recently digesting this post.

In it Bobince comments

these days, you don't really need to ask the question “was my unsolicited popup blocked?”, because the answer is invariably “yes” — all the major browsers have the popup blocker turned on by default. Best approach is only ever to window.open() in response to a direct click, which is almost always allowed.I'm quite happy to buy into this principle because I simply want my popup to open.

What is causing some browsers to see my code as unsolicited?

I'd appreciate any help you could give me. (as you might have guessed, client side is not my bag and this topic has been bugging me for ages).

Many thanks in advance (and fingers crossed) Giles


No much you can do. You could ask your users to disable pop-up blockers or inform them that a pop-up blocker is enabled by checking the window object ref returned by window.open()

e.g.

var w = window.open('http://domain.com');
if(!w) { 
   //an alert in this example
   alert('oops..seems like a pop-up blocker is enabled. Please disable');
}

you could find another way and try what Brad suggests.


There isn't anything you can do about this. Some popup blockers still block everything, even in response to a user clicking. The best you can do is suggest your users turn off popup blockers, or find a different way to do what you want to do. A popular method is the div that appears on top of all others on your page, like Lightbox.

There are many jQuery plugins which make this easy.


You have (at least?) 2 options to deal with this:

  • if you want to keep using popups, display a very visible warning for your users, pointing them to instructions on how to configure their browser to whitelist your domain (like the banners that appear on top of StackOverlow.com when you gain new privileges, or even like the banners Chrome is showing for actions - they are web-based as well);
  • use an iFrame and load its content based on your user's click.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜