javascript - Stop all the code and continue afterwards, like an alert() in JS -


let me explain: when call alert() in js, code in below of alert, stop , when click in ok, code returns work.

i make own custom alert code:

function calert() { var bon; this.show = function (content) {            bon = true;     document.write('<div id="turnofflight"></div><div id="calertbox"><div id="calertimagebox"><img style="position: absolute; top: 54%; left: 50%; margin-top: -32px; margin-left: -32px;" src="images/vectors/1429744831_678136-shield-warning-64.png" alt=""/> </div><div id="calertcontentbox"> </div><div id="calertbuttonbox"><input id="calertbuttonstyle" type="button" value="ok" onclick="calert.ok()" /></div></div>');     $("#calertcontentbox").html(content);     $("#calertbox").show();     $("#turnofflight").fadein("fast");      var div = document.getelementbyid('calertbox').offsetwidth;     var res = -math.abs(div / 2);     document.getelementbyid('calertbox').style.margintop = res + "px"; }; this.ok = function () {     $("#calertbox").hide();     $("#turnofflight").fadeout("medium");     bon = false; }; } 

and in other pages:

<head>     <script src="scripts/jquery_1.11.2.js" type="text/javascript"></script>     <script src="scripts/calertscript.js" type="text/javascript"></script>     <script type="text/javascript">var calert = new calert();</script> </head> 

but have problem, in login page, after call calert(), call this:

echo "<script>javascript:history.go(-1)</script>"; 

to return last page, when used using alert(), after user click in ok, browser return last page, using calert, browser returns last page.

what want user need click in ok button code continue alert().

change calert.show(content) calert.show(content, success). change calert.ok() calert.ok(' + success + '). change this.ok = function () this.ok = function (success), , add success(); end of ok() function.

this call success when button in calert clicked.

instead of calling calert.show("text") need call calert.show("text", function() { javascript:history.go(-1); } ).


so code should be:

function calert() { var bon; this.show = function (content, success) {            bon = true;     document.write('<div id="turnofflight"></div><div id="calertbox"><div id="calertimagebox"><img style="position: absolute; top: 54%; left: 50%; margin-top: -32px; margin-left: -32px;" src="images/vectors/1429744831_678136-shield-warning-64.png" alt=""/> </div><div id="calertcontentbox"> </div><div id="calertbuttonbox"><input id="calertbuttonstyle" type="button" value="ok" onclick="calert.ok(' + success + ')" /></div></div>');     $("#calertcontentbox").html(content);     $("#calertbox").show();     $("#turnofflight").fadein("fast");      var div = document.getelementbyid('calertbox').offsetwidth;     var res = -math.abs(div / 2);     document.getelementbyid('calertbox').style.margintop = res + "px"; }; this.ok = function (success) {     $("#calertbox").hide();     $("#turnofflight").fadeout("medium");     bon = false;      success(); }; } 

and:

<head>     <script src="scripts/jquery_1.11.2.js" type="text/javascript"></script>     <script src="scripts/calertscript.js" type="text/javascript"></script>     <script type="text/javascript">         var calert = new calert();         calert.show("text", function() { javascript:history.go(-1); } );     </script> </head>