2

I created a simple JavaScript function to display my pop-up window once it loads. But it keeps on being blocked by Firefox and Google Chrome and I have to somehow enable it on the Firefox and Chrome to display the pop-up.

Are there any alternatives for this?

I have a player on the pop-up window so I have to use a pop-up to let the player play automatically. The problem is that if I put it on the page itself, once the user clicks another page the entire page reloads and the player automatically stops for a few seconds until the whole page reloads and I have to prevent this from happening.

pnuts
  • 58,317
  • 11
  • 87
  • 139
Agent Smith
  • 23
  • 1
  • 7
  • 6
    You can't. You can change your popup so that instead of a window it uses a floating `div` – jasonscript Jul 25 '14 at 02:37
  • I see but I can't. Once he/she switches to another page, the floating div refreshes also. – Agent Smith Jul 25 '14 at 02:45
  • 1
    If they switch to another page then they don't want to see your content – jasonscript Jul 25 '14 at 02:46
  • You need to tell the problem to either "enable pop ups for this domain" or figure out a different solution like framing your site like people did in the 90's or learn about this 10 year old technology called Ajax with a single page app. – epascarello Jul 25 '14 at 03:16
  • Actually, that would be pretty useful and I've recommended it in the first place but they won't accept it. They say that some other porn websites have these pop-ups that the browser didn't block upon loading the porn page. – Agent Smith Jul 25 '14 at 03:45

3 Answers3

2

The general rule is that popup blockers will engage if window.open or similar is invoked from javascript that is not invoked by direct user action. That is, you can call window.open in response to a button click without getting hit by the popup blocker, but if you put the same code in a timer event it will be blocked. Depth of call chain is also a factor - some older browsers only look at the immediate caller, newer browsers can backtrack a little to see if the caller's caller was a mouse click etc. Keep it as shallow as you can to avoid the popup blockers.

Please take a look at dthorpe's answer here. It covers your question.

Dave Cousineau
  • 12,154
  • 8
  • 64
  • 80
Avinash Babu
  • 6,171
  • 3
  • 21
  • 26
  • I see. So that's why when I try something like create a function where once the page loads, it clicks a button and that button shows the pop-up blocker. – Agent Smith Jul 25 '14 at 03:39
  • 1
    Only if the user is the one that clicked. If you programmatically cause the click, that doesn't count. It must be an action caused directly by the user. – Kevin B Jul 25 '14 at 03:39
1

You could try putting the player on the original page, and using something like History.js to control page changes (you could have the main page body in one wrapper div that changes, and leave the player outside of it).

Otherwise, you could try (assuming you meant a HTML5 <video> or <audio> player) downloading the data to localStorage/cookie/[other persistent storage mechanism] and have it seek everytime you change a page.

It will be hard to stop browsers from blocking your pop up window, because any way to do so is inherently exploitable; however, if you call the function to open another window from an onclick event, you may be able to circumvent some popup blockers. Also, some popup blockers allow popups when using the https protocol, although not many have this feature, and https can be hard to implement for the average website, if you don't have physical access to the server.

One other option is to open the other page in another tab (like this w3c example; you can 'click' the link with javascript).

You might also want to look at this post, as it is somewhat similar.

Community
  • 1
  • 1
mailmindlin
  • 616
  • 2
  • 7
  • 25
  • Yes, its kinda hard to prevent the pop-up window from being block. I could use something like instead of create a menu, I could change them into a CSS tab so that the page wouldn't have to reload once the user goes to check the other pages of the website. Some say that JSON will also work. But then again, I have to minimize these changes because the web application that I use to create the website is joomla.. – Agent Smith Jul 25 '14 at 03:43
1

I only just discovered you asked this question.

Here's the answer in full.

Basically, you can simply create the popup immediately as the user event is fired, then fill it with content (your player, for instance) as you have it available.

Community
  • 1
  • 1
Swiss Mister
  • 3,260
  • 2
  • 20
  • 42