Click here to Skip to main content
15,998,382 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
var ALERT_TITLE = "Message";
        var ALERT_BUTTON_TEXT = "Ok";

        if (document.getElementById) {
            window.alert = function (txt) {
                createCustomAlert(txt);
              
            }
        }
      
        function createCustomAlert(txt) {
            d = document;

            if (d.getElementById("modalContainer")) return;

            mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
            mObj.id = "modalContainer";
            //mObj.style.height = d.documentElement.scrollHeight + "px";

            alertObj = mObj.appendChild(d.createElement("div"));
            alertObj.id = "alertBox";
            if (d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
            //alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth) / 2 + "px";
            alertObj.style.visiblity = "visible";

            h1 = alertObj.appendChild(d.createElement("h1"));
            h1.appendChild(d.createTextNode(ALERT_TITLE));

            msg = alertObj.appendChild(d.createElement("div"));
            msg.id = "alertMsgContainer";
            //msg.appendChild(d.createTextNode(txt));
            msg.innerHTML = txt;

            btn = alertObj.appendChild(d.createElement("a"));
            btn.id = "closeBtn";
            btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
            btn.href = "#";
            btn.focus();
            btn.onclick = function () { removeCustomAlert(); return false; }
           
            alertObj.style.display = "block";

        }

        function removeCustomAlert() {
           
            document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
        }


What I have tried:

I Make A Custom alert box but custom alert not hold script ,normal alert hold script till user not clicked ok .In My Case only show alert and execute full function not wait.
I Want my custom alert open and when i clicked ok then rest of function execute till then function delay.like normal alert working.
Thanks,
Shiavm
Posted
Updated 14-Feb-16 22:51pm
v2

1 solution

You cannot stop the execution of code. Chrome and FireFox will not allow it. What you can do is have your OK button call a function and the continue processing from there. Or use the built-in alert.

Alternatively, look into Dialog | jQuery UI[^] instead of writing your own.
 
Share this answer
 
Comments
Member 11897598 15-Feb-16 9:21am    
Hey Ryan it is not posible m i call a function on click on ok because this function work globally.please tell me other way like normal alert working fine and stop execution .if user click ok then rest of code are executed.please send me if u have any code sample related this
ZurdoDev 15-Feb-16 9:30am    
Sorry, chrome does not allow it. There is a jquery plugin that works in chrome and the way it works is it throws an unhandled error. This causes chrome to stop. It then stores in a string the rest of the code in your function and then calls it after you click OK. It's ugly but it's the only way around it.
Member 11897598 16-Feb-16 3:55am    
cause jQuery UI Modal box DOESN'T pause Jquery code execution waiting for user's click (like alert does).If anybody have solution please send me related code sample.
ZurdoDev 16-Feb-16 6:45am    
That's what I'm telling you. You cannot do it. The browsers no longer support it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900