2

I'm implementing social auth. When the user clicks on a button, I send a command so I can call window.open().

Looking at this call-stack, we can see that the port handler is called in the next event loop: enter image description here

Since window.open is not being called within the click event lifecycle, browsers like safari do not allow for the popup to show up.

What is your approach?

Daniel Birowsky Popeski
  • 8,752
  • 12
  • 60
  • 125
  • Could you create an [iframe](http://package.elm-lang.org/packages/elm-lang/html/2.0.0/Html#iframe) overlay in Elm with the src set to the relevant login page? – Simon H Apr 08 '17 at 14:59
  • @SimonH nah, it's a [security concern](http://stackoverflow.com/a/9089070/592641) – Daniel Birowsky Popeski Apr 08 '17 at 15:01
  • Are you using some sort of event batching framework? Calling window.open through a port in a click handler does work normally. – dta Apr 08 '17 at 16:04

2 Answers2

6

It's not super pretty, but you can do something like

a 
    [ Html.Attributes.attribute "onClick" "window.open(this.href, this.target, 'width=800,height=600'); return false;" ]
    [ text "Click me" ]
amitaibu
  • 1,026
  • 1
  • 7
  • 23
1

It's an underhanded way to handle this, and not 100% strictly guaranteed to continue working in future elm releases but I've done this more than once in a pinch:

https://medium.com/@prozacchiwawa/the-i-m-stupid-elm-language-nugget-7-8d3efd525e3e

A property getter on the DOM node type can be triggered by a json decoder during event handling. You can run whatever code you want as a side effect of accessing it. The object being accessed by the json decoder is the real event object on the event handler stack as things are now.

Art Yerkes
  • 1,274
  • 9
  • 9