Javascript to close browser window simultaneously with dialog box - javascript

I'm working on an asp.net web form. This form has a button to open a new window (report window) and show a report. But first the user has to select a client from the list in the form before he/she can see the report. For validation matter, I use code to check whether the user has selected one of the client or not, the validation is done in the new window (report window).
The validation is set to show a javascript dialog box if the user hasn't selected one of the client, it's working fine, the dialog box show the message with a single OK button. Is it possible to close the window concurrent with the dialog box when the user click the OK button ?

Not with an alert window (you cannot get the event when the user clicks ok), you need either
a confirm instead of an alert so you can react on the event
or a "self-made" dialog like jquery dialog http://jqueryui.com/demos/dialog/ there you can react on the click event
And then just close the window with window.close()

Related

'Confirm' popup default value when blocked by browser

Is it possible to provide a default value for a basic javascript 'confirm' popup if the user has chosen to block popups in their browser (such as Edge)?
I'm looking to add a very simple confirm dialog on a web application to confirm an element is to be deleted.
Right now, I just have this line before the delete action :
if (!confirm("Delete this element?")) { return; }
// Code to delete the element here
Ideally, if the user chooses to block popups on their browser, the confirm popup should simply delete without further requests.

Browser Tab Close Event for javascript or jquery

I have added a div which contains some survey questions which is initially hidden. Once the user closes the window or navigate away from the page, I need to popup the survey div to get the confirmation. I know there is a browser default confirm box method by using onbeforeunload event. But I need to popup the div rather than the browser default confirm box. Is there any way to do this? (or is there any way to interrupt the close event without even clicks on the "Stay on page" button found in the browser default confirm box?)
UPDATE : it seems we cannot do the action you are asking. There are some solutions to cover this in IE but overall its not possible. Ignore all the previous code.

Having difficulty closing a PopUP window, after update and submit button

So, I have a javaScript that calls an ASP page, using ShowModalDialog ... it works great, passes the correct information, the user is then prompted with radio button to answer a question, then if the user presses "submit" ... the data is written to a SQL table. this all works; however, I cannot get the window to close. The behavior is the program opens another page (same content as in the window popUP) only it is full page size.
When I tried to add the following code: Response.Write("script language='javascript'?window.close();") ... I get the same behavior with a message indicating that the program is trying to close the window.
this is so frustrating because I don't understand why closing a window is so diffcult.
Please help if you can.

Javascript - Closing confirmation message if no response from user

I have got asp.net 2.0 website, in which I display session timeout through confirm message box, asking user to select ok or cancel.
Problem: if user doesn't provide any input (assuming his desktop is locked and he is out for lunch) - then how can I close this confirmation message and display another pop-up or re-driect to login page
Regards
If you are using the native browser confirmation box you cannot dismiss that, the user would need to do so. If you create your own, then you can use setTimeout to dismiss after a certain amount of time
As haslama suggested that you will have to create a custom alert as you can't dismiss the browser confirmation box.
As an alternative you can show a div based message to user instead of an alert, and in that div user can select OK or cancel and you can implement timeout for that div.

Clicking OK in a prompt

I know how to create alerts and confirm boxes, but what I cannot find out how to do is to do the actual clicking of OK. I have a page that pops up a confirm box. I want to click OK using a Java Script add-on. Basically, I want my code to click a link on the page, then click ok when prompted. Is that possible?
That's not possible with a browser pop-up.
However if it's a modal dialog that sits within the DOM of the page, then you can trigger a JavaScript event to close it. An example of such a dialog is jQuery's dialog.

Categories

Resources