1

I have this button that's supposed to open a random wikipedia page. In the codepen editor everything works fine, but when I open it full-page, the random button doens't work anymore and in the log it says 'window.open is disabled'.

Looking around I saw that it might be because I was calling the window.open inside an ajax call, which is asynchronous and therefore not allowed (Bypass popup blocker on window.open when JQuery event.preventDefault() is set) so I collect the url in the ajax call and call the window.open(url) inside the jquery .click function, but again: it works in codepen editor but not in the full-page version.

So I tried a simpler version, which still doesn't work:

 $('#random').click(function() {
  window.open("http://en.wikipedia.org/wiki")
})

I don't think it's a browser misconfiguration, because it wouldn't work in the editor either, and that's not the case. Tried with both chrome and FF.

Any idea or workaround?

Community
  • 1
  • 1
NicolaF
  • 127
  • 1
  • 11
  • Do you have any other JS libraries/SDKs/whatever embedded? Live example? – CBroe Jul 24 '15 at 16:41
  • I only added bootstrap and jquery Here the full-page http://codepen.io/ni-kun/full/RPewRV/ – NicolaF Jul 24 '15 at 16:43
  • if codepen, could you post the link here? –  Jul 24 '15 at 16:44
  • Then it’s probably codepen overwriting the `window.open` method, with one that just logs the message to console. – CBroe Jul 24 '15 at 16:44
  • So I should assume there's nothing wrong with my code? But shouldn't the compiler do the same job in both the editor and in the full page view? – NicolaF Jul 24 '15 at 16:45

1 Answers1

2

There's absolutely nothing wrong with your code; it gives me window.open is disabled as well.

CodePen disables window.open so your best bet would be to experiment locally.

Nebula
  • 6,614
  • 4
  • 20
  • 40
  • Thanks for taking the time to look at it @towerofnix. It's really weird there isn't any note or mention about this around though, codepen it's widely used and I'd say window.open it's a pretty standard operation. Oh well, mystery solved anyway. – NicolaF Jul 24 '15 at 18:04
  • Yep, hopefully they make it so that it's more clear. At least change the message from `window.open is disabled` to `CodePen disables window.open`, you'd think? – Nebula Jul 24 '15 at 18:06