javascript - How to use sweetalert in a .js file -
so have .js file, , i'm trying throw message user using sweetalert. moreover, want load .js , .css files of sweetalert, dynamically inside .js file.
// load script var filerefjs = document.createelement('script'); filerefjs.setattribute("type", "text/javascript"); filerefjs.setattribute("src", "../../rotatescreen/dist/sweetalert.min.js"); // load css file var filerefcss = document.createelement("link"); filerefcss.setattribute("rel", "stylesheet"); filerefcss.setattribute("type", "text/css"); filerefcss.setattribute("href", "../../rotatescreen/dist/sweetalert.css"); if (window.innerheight < window.innerwidth){ window.onload = function(){ document.getelementbyid('b6').onclick = function(){ swal({title: "", text: "message", imageurl: "../../rotatescreen/example/images/rotate.png", confirmbuttontext: "ok"}); }; } } // if
i don't errors, alert-box not appear on screen .
your code looks correct (according there website). double check you're linking sweetalert.js file correctly. have @ console in chromes developer tools , make sure there no errors, display if there unlinked files or missing files.
i tested bit of code , works fine inside .js file
sweetalert('error', "enter valid email please", 'error');
Comments
Post a Comment