I try to integrate to my ELM page a "login with" widget (the one from Telegram https://core.telegram.org/widgets/login)
I try to build the appropriate node, which is of type <script>
, but when the page is rendered, the type is replaced by <p>
. I guess this is a security feature. But how can I build this node ?
What I want:
<script
async
src="https://telegram.org/js/telegram-widget.js?21"
data-telegram-login="botname"
data-onauth="onTelegramAuth(user)"
></script>
What I do:
telegram : Html Model
telegram =
node "script"
[ attribute "async" ""
, attribute "src" "https://telegrami.org/js/telegram-widget.js?21"
, attribute "data-telegram-login" "botname"
, attribute "data-onauth" "onTelegramAuth(user)"
]
[]
What I get:
<p
async=""
src="https://telegrami.org/js/telegram-widget.js?21"
data-telegram-login="botname"
data-onauth="onTelegramAuth(user)"
></p>
Thank for your help 🙂
2
Answers
This is intentional. Elm doesn’t allow
script
tags for security reasons. If you want that kind of functionality, wrap it around in a web component and import the web component in Elm. You can listen for Custom Events on Elm side in order to pass data from the web component to Elm and you can set attributes to the web component in order to pass data from Elm to the web component.Thanks to @pdamoc,
I’ve managed to make it work like this:
Web component:
telegram-button.js
Import it inside your
index.js
Then in Elm