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.
Related
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>
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
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...
I am new and apologies if i asked age old question. I have a problem with an asp.net web application, as follows:
Problem:
On Page 1 i need to enter details and click next button to go to Page 2
If i had any validation error(s), i clear them and then click next button
On Page 2 if i click BROWSER BACK button, i would expect to see corrected details on page 1 but it loads the Page 1 WITH VALIDATION ERRORS.
More information:
The aspx of Page 1 alread has meta tags with expire set to -1 and 'no-cache' set for both cache-control and pragma properties.
On IE 8, i get 'page expired' page but on firefox 8, it automatically refreshes the page instead of showing 'page expired' page.
The issue seems to be there even on IE, when i try to refresh the page manually, i could see the old validation errors similar to FIrefox behavior.
Out of curiosity i entered improper details on page 1 in such a way i am hampered by validation errors 3 times. Then i correct details and clicked next button to reach Page 2.
On page 2 on clicking browser back button, i will get the validation errors i recieved on THIRD TIME, or the latest version of page 1 with vlidation errors.
However browser back button works fine when there were no validation errors on previous page.
Sorry for writing so much info, just thought might give you more insight into the problem.
Sounds like you are trying to create a wizard-like process where you take the user through multiple steps (pages) before the end goal. If that is the case, the way I've handled that in the past is through the use of Panel tags. Add a Panel tag for each step in your process and add your form elements to each. You can also have a "Next" button to progress to the next step within each Panel. When the button is clicked, hide the current Panel and unhide the next. You can also apply validation logic to the button to prevent the user from advancing with bad input. At the end, you can redirect them to a different page for a "success" message or summary. If the success page was also another Panel on the page, the user would be able to resubmit the form by refreshing the page if not handled correctly.
We've done this a lot and have never run into validation issues like the kind you are describing. I hope this helps you a little.
I have some simple code to display a confirm dialog box when the user tries to leave my form:
window.onbeforeunload = askConfirm;
function askConfirm(){
return "Your answers will be lost.";
}
But this is a multi-page form and they frequently press back to change some values on a previous page.
But when they do this dialog box still comes up.
Is there a way around this?
The answer I would suggest unfortunately doesn't actually answer your question but is a solution of a kind. The only possible solution here, imv, is to make sure that a user clicking the back button doesn't actually create an issue by storing the form answers from all pages. In the case of PHP I would store them in a session ($_SESSION). You have to recognise that users use the back button more than any other UI element within a browser. If your form truly has to be across a number of pages then you need to make sure the data they have entered is persistent across all these pages. I would actually provide a navigation for this within your own interface. Provide a clear sequential process visually and allow instant navigation through this process where possible.
I don't see a way to specifically detect whether the user pressed "back" or any other browser button. This is outside the site's scope.
Only one solution comes to mind: Show the confirmation dialog only when a global flag has been set to "true".
if (ask_when_exiting == true)
return "Your answers will be lost.";
You would have to set the variable to true? in the onclick event of every link that you want the confirmation to pop up for. You should be able to mass apply this event to every link on your page using JQuery or another JS framework (Seomthing like $$('a').each()....).
However, this will disable the confirmation for reloading the page, or any other event that is not triggered using a control on the page like typing in another URL or closing the browser, as well.