Click here to Skip to main content
15,914,419 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Team

This is my question:-
how can automatically ok event is trigger when alert box is shown on page in javascript.
i want when alert box is show then after few second auto click event of ok button is
fire without clicking or press any key in javascript/ jquery
Posted
Comments
F-ES Sitecore 1-Dec-15 7:01am    
Implement your own alert function, or use an alert plug-in that supports this feature.
Sergey Alexandrovich Kryukov 1-Dec-15 13:12pm    
Perfectly agree. This is the only way to go. In Solution 2, I explain some additional detail on how to achieve that.
But on top of that, I would recommend to review this design feature, it can be very annoying to the users.

Of course, I credited your comment.

—SA

This would be wrong approach. See also the reasonable comment to the question by F-ES Sitecore.

JavaScript alert call is blocking. If you want to bypass it, call it conditionally, so you would either perform the call or not. For showing some content for few second, use the timer and some HTML element on the same page. You can temporarily disable all controls of the current document.body, show some element with the information you wanted to present using alert, wait few seconds of time and then remove this element from the DOM tree. You can even perform the dimming: cover all the area of the current window with some element with absolute positioning and set its opacity level to some value between 0 and 1. Don't forget to handle the window.resize, to adjust size/position of your two elements, the "dimmer" element and your message element.

This feature is quite easy to develop, but I'm sure you will be able to find some available implementation.

[EDIT]

Recently, after I already answered this question, I published an article on the topic. Please see: Modal Popup From Scratch[^].

[END EDIT]

But I have a much better suggestion: change your UI design. Most users will be highly irritated when something disappears without their consent. What you may need is the usual "modal popup" which is removed by the user click, not by timer, such as one implemented as a jQuery UI Dialog Wizard: https://jqueryui.com/dialog[^].

There are many 3-rd party plug-ins collectively known as "modal popup" control elements; they feature many different visual effects, including dimming.

Moreover, I would advise you to re-thing even the idea of showing an alert. Even though there are many cases when it is really important, there are many arguments against them, and many alternatives. I don't mean not using such things, I mean using them with care, only in some very special cases. Most people dislike when something interrupts their workflow. I don't know your exact situation, so you decide.

Also note that JavaScript functions like alert, confirm and prompt are hardly acceptable for real production versions of Web applications. They are too inflexible and ugly. Well, alert can be useful during development or, at best, for showing exception information, and only in the cases when it propagates to your piece of code due to some unfixed bugs.

—SA
 
Share this answer
 
v3
Click

window.alert = function(){
return true;
}

But this case your alert message is not display on your page.
but it work properly
 
Share this answer
 

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