Sweetalert2: HTML Field, invoking JS within the embedded html.

Created on 16 Jul 2017  路  4Comments  路  Source: sweetalert2/sweetalert2

Hi,

This is a great library ! Thank you so much.
This is not an issue, but rather a question; I apologize if this is the wrong place, ..
My question is on regards to the HTML field on sweetalert2;
I have a rather large block of html, and instead of ' I call a JS function, like this:

swal{(...........
.
.
.
html: document.getElementById('htmlappender').innerHTML
.
})
and the htmlappender element is this:

and that works great, I can insert large blocks of HTML without having to concatenate
lots of strings;

However, how would I go about if the embedded HTML needs to invoke JS ... ?
for example,
if I change the above element to:

< script id="htmlappender" type="text/html">
< h1 style ="color:red">Hello

     CallJS(); // is interpreted as content

< /script >

I also tried a button,invoking js using the onclick event, but also to no avail;

Ideally there shouldnt be a need to click a button, ...

essentially: How to I embed JS within the embedded HTML via the swal .. html: field ?

Thanks in advance for your kind attention, and thanks for this great library !
best regards,
s

All 4 comments

If your issue is focused more on 'how do I do this?' rather than 'this is a broken functionality', then either ask on our Gitter or submit it to StackOverflow instead of GitHub, and make sure you add the sweetalert tag to the question.

See Contributing.md

thanks for replying. my issue is not about how to do it, but rather to verify if swal html field can or cannot handle embedded js object within the passed html,
however if the swal htm field is supposed to handle an object as described above, then I'd say it would be a broken functionality, given that I have no problem doing that outside swal, unless you have an example ? if you say no, then that's it, but if you say yes then obviously the problem is me, at which point Id open a question externally....thanks again for replying, txs
tx

In that case please come up with the jsfiddle for your question

JSFiddle template: https://jsfiddle.net/limon/ad3quksn/

See Contributing.md

With all due respect, you could have said 'yes it's possible' or 'no it's not possible'...
it is pointless to have such a great library when the fundamental point of sharing knowledge is
pushed away with, and I apologize to say: arrogance.
thanks for your reply anyway.,
ps: anyone else looking for the answer: the answer is yes, but there is a modification on
one of the .js; feel free to ping me. txs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

limonte picture limonte  路  3Comments

gouhary picture gouhary  路  3Comments

PrestaShark picture PrestaShark  路  3Comments

mayvn10 picture mayvn10  路  4Comments

jharrvis picture jharrvis  路  3Comments