How can I cancel an alert box? - javascript

I can display an alert box as follows: alert('Please wait 5 seconds');.
Is there a way to remove this alert box after 5 seconds if the user has not clicked "OK" by that time using JavaScript?

No, you cannot do that.
As an alternative you could create some sort of modal window right in your UI.

When a native JS alert dialog is fired the browser stops everytihng, until the user clicks "OK", this goes for the confirm() funciton as well.
I recommend using jQuery's UI dialog component:
http://jqueryui.com/demos/dialog/
Highly configuratble, modal, non modal, size, and of course for your use... timed interval. Heck you can even ad a nifty timer that counts down!

As far as I know there is no way to do this using the browsers alert window. JavaScript cannot be executed when an alert box is "Alerting". However you could use a UI element with a close() method, as the displaying of such an element would not stop the browser from executing your JavaScript.

The alert can not be removed, what you can do is to make a custom alert using jquery. With jquery, you can customize your alert theme and decide how its going to be removed with a simple command like fadeOut();

This may not help the poster at all but I bet some finders readers will get through fire and flames out with this : reload the script the alert box is displayed from.
To do this you should add an invisible frame from which the alert box is fired, and reload that frame without affecting your dear front page... Not even sure if that works I'll go try and come back to this...

Related

Web Design - Modal CSS Change to Display Block on Site Exit

I am trying to implement an easy way of displaying a small modal window when the user exits my Website, containing a quick and easy single question dialog, with a multiple-choice answer, and a submit button..
I'm having trouble finding a simple, straight-forward answer everywhere I've looked. Yes, I searched.
NOTE: I already have my Modal Window created, with the Form on it, and everything ready! (currently the Modal Window is set to Display None, until I figure out the following question)..
What I need to know exactly is this: What is the easiest way to simply detect when the user is leaving my website, and set the Property of the Modal Window ID to Display:Block for example, which would change it from Display:None and make it show?
I would prefer a simple script being able to detect any of the following behavior as they are trying to exit the website either by (A) clicking X on the tab, (B) clicking X on the window, or (C) hitting the back button enough times to leave my Site - at which time, the script would change my Modal's ID property from display none, to display block.. Thats it.
Thanks in advance!
JavaScript has a special event for this onbeforeunload
<script>
window.onbeforeunload = exitFunc;
function exitFunc() {
modal logic here
}
</script>

asynchronous __doPostBack

Requirement
In User control ( In single update panel) - user will change some data and click on button or link button other than save button
We prompt Dialog box to user for (Yes/No/Cancel)
On cancel we did nothing and remain on same page
On No - we redirect/process further without saving data.
On Save we have to save changes and redirect/process further.
Here the problem is with Save
We have different panels on page (same on user control)
On Selection of Yes, Here we call "_doPostBack" for save button click event (Works fine), and in same javascript function below save postback calls other "_doPostBack" to hide current panel (Panel-1) and show another one (Panel-2) and server side process.
But Its always shows (Panel-1)
However in FF, Panel-2 just prompt and hide again.
EDIT: Hide panels are at server side, as there are multiple buttons which shows/hide panels.
Expected result is : After save data, show Panel-2 and hide Panel-1
can anyone has idea how to overcome this prob ?
Without some actual code it is a bit difficult to see what is going on, but from what I understand it is a problem with timing.
When you click 'Yes', you perform the postback function and immediately after you hide the panel.
Your 'doPostback' is actually a-synchronous. Meaning the response comes a bit later (not immediately). Thus when the response comes back it updates your page and that is where you flow is breaking up.
FF is probably fast enough to actual show you what is really happening. Your hide function works ok, but is overwritten by the ajax response.
I suggest you hide the panel asynchronously, with the response that comes from the server.
Here are some links on that:
- RegisterClientScriptBlock within AJAX method call
RegisterStartupScript doesn't work with ScriptManager,Updatepanel. Why is that?
I hope this helps you get on the right track.
Good luck

How to make the Background behind Alert Box clickable?

I have a application where i make all Divs clickable by using this code :
$("html").click(function(){
alert("Click");
return false;
});
This one work normally for all divs. Well, when Alert popup, the Background behind alert box cannot be clicked. How can i turn that to be clickable too?
PS: Right Click on the Background dont work too.
Thats not possible. You have to use a JS plugin doing the alert, so you can influence the behaviour (like the jquery ui modal widget, mentioned here). But with the browser alert this is not possible, as far as i know.
Not sure how to do exactly what you're asking (if it's possible). Maybe someone else can shed some light on that.
But a solution you could look into would be the dialog widget from jQuery UI. You can easily create pop-ups, modal or non-modal (meaning with the background faded out or not).
http://jqueryui.com/dialog/
They have some demos there, but it's as simple as created a div with some text and calling...
$("#the_div_id").dialog();
Other config parameters can be found from the API:
http://api.jqueryui.com/dialog/
By default its modal popup behaviour ,If you want to clickable
Assuming you are using Jquery Ui dialog
Try with the option modal
$('#selector').dialog("option","modal",false);
http://api.jqueryui.com/dialog/#option-modal

"Prevent this page from creating additional dialogs" on the second click

I have a weird problem in javascript alerts in my application. On a button click, alert displaying with an ok button. For the second click , i am getting a sentence with a check box "Prevent this page from creating additional dialogs" .
I know this a feature of browser. But for all other sites this is displaying after 10th click. For my application this is coming for the second click .Please help.
The alert is coming as a result of ajax call.
if (result.message!=null && result.message!=''){
alert(result.message);
}
I found the problem coming only when the time between clicks is less than 4 seconds, Any opinion how to increase this .?
Most common browser implement such a feature in order to prevent alert spam. Use another notification method, for example an absolute positioned div.
The jQuery.UI dialog module could give you some ideas.

jQuery Facebox delay

I need a very FAST and lightweight jquery based Modal box on my site, I am looking at Facebox http://famspam.com/facebox
It is a nice plugin and it seems fast and lightweight but I think I can still strip out some of the features I do not need. For example I do not need it to use regex and find photos, so I have removed that part of the code, also I do not want the box to close whenever you click anywhere or the escape key. I have this partially done, I removed the code that makes the escape key close the box but I have not figured out how to make it only close programaticly or when clicking the close button only, right now it closes on any click outside of the box.
Now I have one issue I have not been able to figure out yet, there appears to be 2 spots in the code that control the delay of fading the box in and out, they were set at 200 and I changed them to 0 and tried several other number combinations but I can not seem to get the speed to be faster (less delay).
Does anyone know how to remove the delay in opening a facebox? Also how to disable it from closing when you click anywhere outside of the box?
To disable closing it from clicking anywhere outside,
you can find something called "overlay : true"
change it to "overlay : false,"
To close it with-out delay, You can find something like '$(document).bind('close.facebox', function() {'
there, change
"$('#facebox').fadeOut(function() {"
to
"$('#facebox').hide(function() {"
I use the thickbox for one project, pretty fast. Check also this list. I recommend you to keep the closing by clicking outside the box option, a real help for users.
Instead of hacking facebox, I would try something more configurable.
I've used jqModal to create modal boxes, which display instantly, can't be closed except when certain conditions are met, etc

Categories

Resources