electerious / basicLightbox

The lightest lightbox ever made.

Home Page:https://basiclightbox.electerious.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Scripts within lightbox doesn't work

criocere opened this issue · comments

commented

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?

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'));