Calling window.open through port

坚强是说给别人听的谎言 提交于 2020-01-23 12:04:45

问题


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:

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?


回答1:


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" ]



回答2:


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.



来源:https://stackoverflow.com/questions/43295502/calling-window-open-through-port

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!