electerious / basicLightbox

The lightest lightbox ever made.
https://basiclightbox.electerious.com
MIT License
557 stars 55 forks source link

Scripts within lightbox doesn't work #39

Closed criocere closed 3 years ago

criocere commented 3 years ago

Im trying to display a lightbox with some javascript but this doesn't work

Working example basicLightbox.create('<div style="background-color:#fff;padding:10px;max-width:500px;border-radius:5px"><p>HTML</p><script type="text/javascript">alert("hello");</script></div>').show();

None working example basicLightbox.create('<div style="background-color:#fff;padding:10px;max-width:500px;border-radius:5px"><p>HTML</p></div>').show();

Is it an issue?

electerious commented 3 years ago

basicLightbox just adds the HTML to the DOM. It's possible that the JS won't execute that way. Remember that you're already in a JS context and there's no need to run JS in the lightbox. You can simply run your code after showing the lightbox. The .show() function accepts a callback: https://github.com/electerious/basicLightbox#showcb

basicLightbox.create('<div style="background-color:#fff;padding:10px;max-width:500px;border-radius:5px"><p>HTML</p></div>').show(() => alert('hello'));