How to handle "Are you sure you want to leave this page" popup using watin - watin

How to handle "Are you sure you want to leave this page" popup using watin
I have open one link,after that when i open another link it gives a popup like
"Are you sure you want to leave this page"
how to handle this popup in watin.

WatiN.Core.DialogHandlers.ReturnDialogHandler.CreateInstance().OKButton.Click(); //IE8 or below
WatiN.Core.DialogHandlers.ReturnDialogHandlerIe9 ie9Handler = new WatiN.Core.DialogHandlers.ReturnDialogHandlerIe9(); //IE9
browser.AddDialogHandler(ie9Handler);
ie9Handler.CancelButton.Click();
browser.RemoveDialogHandler(ie9Handler);

browser.RunScript(#"
window.onbeforeunload = function ()
{
event.returnValue = 'Are you sure you want to leave this page?';
}
");

Related

How to trigger UI class for Google Sheets?

My goal
Here is the documentation I'm trying to follow.
// Display a dialog box with a title, message, input field, and "Yes" and "No" buttons. The
// user can also close the dialog by clicking the close button in its title bar.
var ui = SpreadsheetApp.getUi();
var response = ui.prompt('Getting to know you', 'May I know your name?', ui.ButtonSet.YES_NO);
// Process the user's response.
if (response.getSelectedButton() == ui.Button.YES) {
Logger.log('The user\'s name is %s.', response.getResponseText());
} else if (response.getSelectedButton() == ui.Button.NO) {
Logger.log('The user didn\'t want to provide a name.');
} else {
Logger.log('The user clicked the close button in the dialog\'s title bar.');
}
What I expect to happen and what happens instead
I expect the UI to display a dialog box with a title, message, input field, and "Yes" and "No" buttons. The user can also close the dialog by clicking the close button in its title bar.
But instead, nothing happens.
Steps to reproduce.
Open a Google Sheet.
Open Script Editor: Tools > Script editor
Paste above code into script editor.
Close script editor.
Navigate to Google Sheet.
But as I mentioned, nothing actually happened.
How do I trigger the UI instance to initiate? What am I doing wrong?
Run this function:
function runIt() {
var ui = SpreadsheetApp.getUi();
var response = ui.prompt('Getting to know you', 'May I know your name?', ui.ButtonSet.YES_NO);
if (response.getSelectedButton() == ui.Button.YES) {
Logger.log('The user\'s name is %s.', response.getResponseText());
} else if (response.getSelectedButton() == ui.Button.NO) {
Logger.log('The user didn\'t want to provide a name.');
} else {
Logger.log('The user clicked the close button in the dialog\'s title bar.');
}
}
After getting the function to run go look at the spreadsheet.

Confirmation before closing a modal dialog page in Apex 5.0

I am trying to create a simple confirmation ("Do you want to close this window?") when closing a modal dialog page with the (X)-button.
What would be the most efficient way to implement this in Apex 5.0?
I tried to implement a solution using the dialog closed event, this seemed to have had no effects on closing the dialog with the (X)-button, however.
Try to create a dynamic action, on page load, in your modal page with that code:
Your da should execute a javascript code:
var button = parent.$('.ui-dialog-titlebar-close'); //get the button
button.unbind(); //remove the behavior
//put another behavior to the button
button.on('click', function() {
apex.message.confirm( "Your message here", function( okPressed ) {
if( okPressed ) {
apex.navigation.dialog.cancel(true);
}
});
});
Try to confirm if the "X" button have the css class "ui-dialog-titlebar-close", they can change between versions of apex.
If necessary, update the first line of the code with the correct class.
Have you considered hiding the button (x) and canceling the modal dialog page by clicking on the "cancel" button?
If you want to rename the standard button names in the confirmation window, use:
apex.lang.addMessages({"APEX.DIALOG.OK": pOkLabel});
apex.lang.addMessages({"APEX.DIALOG.CANCEL": pCancelLabel});

How to make an AJAX call with Confirm in lift?

I'm new to lift, and want to implement following in my project:
There is a "delete" link in the page, when user clicks it, there will be a confirmation with text "are you sure to delete?". If user clicks on "yes", it will make an AJAX call to delete something on the server side, then show a notice "Operation complete", and after 3 seconds, the page will be reloaded.
How to implement this in lift? I have searched a lot, but not found an correct example.
I can only do this for now:
SHtml.a( ()=>Confirm("are you sure to delete", ???), "delete" )
The easiest way is to use the SHtml.ajaxInvoke in conjunction with JsCmds.Confirm. It will create a server side function and return a tuple with the functionId and JsCmd. So, something like this should do what you are looking to do:
SHtml.a( () => {
JsCmds.Confirm("Are you sure you want to delete?", {
SHtml.ajaxInvoke(() => {
//Logic here to delete
S.notice("Operation complete")
JsCmds.After(3 seconds, JsCmds.Reload) //or whatever javascript response you want, e.g. JsCmds.Noop
})._2
})
}, "delete")
In the above - clicking on the link will trigger the confirmation. If you select OK, then it will issue an ajax call to your function and display a notice. You can use that in any of the SHtml items that require a JsCmd.
If you want to have the page redirect after a timeout, you can just write a client-side javascript function to do what you need and use JsCmds.Run to call it.
Using reactive-web:
confirm("Are you sure you want to do that?") {
case true =>
// handle yes, if so desired
case false =>
// handle no, if so desired
}
See the scaladocs: http://reactive-web.tk/reactive-web-api/#reactive.web.package

How do I close a window after clicking a button?

I am using MVC 3 and I have a button that the user presses to either update some records or to not update some records. I am trying to close the tab after the user presses the No, thank you button. After doing some research all that I have been able to find on this subject is to close a window using jQuery or javascript. I was hoping that there is a way to close the window in the actionLink. I have included the button code below and feel free to ask any questions you might have as I will be checking back often. If you need any other code I would be happy to supply that as well. Thanks for your help!
<div class="message dialog" title="Changes Saved">
You have successfully saved your changes.<br/>Would you like to update the other versions of this Project?
<br />
#Html.ActionLink("Yes, Update Projects", "UpdateProject", "Project", new { id = Model.IAMP_PK }, new { #class = "button2" })
#Html.ActionLink("No, Thank you", null, null, new { #class = "button2" })
</div>
You cannot close the browser from server-side. And I am not sure why you want that when client-side solution is pretty simple.
Change the button to:
#Html.ActionLink("No, Thank you", null, null, new { #class = "button2", id="close" })
Then do
$("#close").click(function() { window.close(); });
javascript is answer as client-side code is only way to close the browser. You could attach a jquery onclick event to the button based on class=button2.
http://api.jquery.com/click/
$(".button2").click(function() {
window.close();
});
How to close current tab in a browser window?
It is very simple to close window or tab which is related to our current project.
After Create a Button with onclick function name(closeWindow)
use the below code.
function closeWindow() {
alert("Your Tab is closing.....");
//window.open('', '_self', '');
self.close();
}

Custom message boxes in WP7

I really like the look/behavior of window created by MessageBox.Show. How can I create one from scratch so that I can add other stuff like a textbox?
There's a good article here on creating your own version, which is now on CodePlex. There various customizable MessageBoxes in the Coding4Fun toolkit. If you want to do it all on your own, this guide might help as well.
Instead of using a MessageBox, you could try using a Popup.
But, you'll have to manually disable the contols on the screen when the popup is open (MessageBox does this automatically for you). Also, you'll have to override the back button behaviour so that back button closes the Popup if it is open. This is also automatically done by a MessageBox.
In Mix11, Laurent Bugnion talked about Mvvm. In hist samples, there is a sample including the implement of Custom MessageBox. u can download the sourcecode from here and check the "03 JsonDemo - WP7 DialogService " sample.
Hope this help u.
Take a look at this custom implementation. Looks and behaves just like the out of the box MessageBox and is easy to use. I've used it in two of my phone apps.
Add references to Microsoft.Xna.Framework and Microsoft.Xna.Framework.GamerServices and then you can do the following:
Guide.BeginShowMessageBox("Title",
"Text",
new List<String> { "Answer 1", "Answer 2" },
0, // Focus button
MessageBoxIcon.Alert,
asyncResult =>
{
int? response = Guide.EndShowMessageBox(asyncResult);
if(response == null)
{
// Back button pressed
}
else if(response == 0)
{
// "Answer 1" pressed
}
else if(response == 1)
{
// "Answer 2" pressed
}
},
null);
I have tested this with Windows Phone 7 and it appears to work.

Resources