I'm writing an app in javascript and html with phonegap/cordova.
I have this code in javascript:
$('#diario_delete_btn').live('tap',function(e){
var iddb = $(this).find('a').attr('rel');
confirm_diario_delete(iddb);
});
function diario_delete(iddb) {
var db = window.openDatabase("Database", "1.0", "123nozze", 200000);
db.transaction(function(tx){
tx.executeSql('DELETE FROM AgendaItemJDO WHERE id='+iddb);
lastChangeUpdate();
});
$('.diario_row[db_id="'+ iddb +'"]').remove();
$('#popupMenuDiario').popup("close");
}
function confirm_diario_delete(iddb) {
var r = confirm("Confermi l'eliminazione dell'elemento?");
if (r) {
diario_delete(iddb);
} else {
$('#popupMenuDiario').popup("close");
}
}
It seems to work but if I choose "cancel button" (so r = false) n times before I press "confirm button", next time the confirm dialog is displayed 2 times, next time it is displayed 3 times, and so on. I don't know why this behaves this way. The same is if a change the code and I use the Cordova example code for confirm dialog.
Any ideas on what is the problem and how can I solve it?
Thanks!
You should use the native notification which Phonegap supports.
Specifically the .confirm() method taken from link above;
// process the confirmation dialog result
function onConfirm(button) {
alert('You selected button ' + button);
}
// Show a custom confirmation dialog
//
navigator.notification.confirm(
'You are the winner!', // message
onConfirm, // callback to invoke with index of button pressed
'Game Over', // title
'Restart,Exit' // buttonLabels
);
navigator.notification.confirm(
'Are you sure you want to signup ', // message
onConfirm, // callback to invoke with index of button pressed
'SignUp', // title
['yes','no'] // buttonLabels
);
function onConfirm(buttonIndex){
alert('You selected button ' + buttonIndex);
if(buttonIndex==2){
alert('You selected button - no');
}else{
alert('You selected button - yes');
}
}
Related
I have a situation where in, when the user clicks the "back" button, I have to prompt for a "confirm" on a page using JavaScript. The result would decide whether to stay on the page or not.
I have used, the following:
window.onbeforeunload = function () {
var answer = return confirm("Please note by clicking the back button will reset your selection")
if (!answer) {
event.preventDefault();
}
else{
// do something
}
};
Now, even if this prompts a popup on the page, the back button can still be clicked taking the user to the previous page.
On the other hand, by using the following.
window.onbeforeunload = () => {return '';}
I get the message "Changes you made may not be saved.", with the prevention of "back", "forward", "refresh" and all such buttons on the page.
I want this same thing (the prevention of these buttons), to happen on "confirm('message')".
function Confirm_something() {
history.pushState(null, null, location.href);
window.onpopstate = function () {
history.go(1);
};
return confirm("Text you want?");
}
if(Confirm_something){
console.log('user say yes'); //then call your save edit or delete functions.
}
else{
console.log('user say no');
}
I'm currently building a chrome extension and I'm trying to get it to be able to stop a like on Facebook from going through even after the like button has been clicked. In my content.js, I currently have the code:
document.querySelectorAll('a[data-testid="fb-ufi-likelink"]').forEach(function(element) {
element.addEventListener('click', function() {
var r = confirm("You clicked like");
if (r == true) {
alert("you clicked OK");
} else {
alert("you clicked Cancel")
}
})
});
As of now, when the like button is clicked, a confirm box pops up but the like does not go through until "OK" or "Cancel" is clicked.
How do I prevent the like action from going through when the 'cancel' button is clicked? Thanks!
Try the following.
document.querySelectorAll('a[data-testid="fb-ufi-likelink"]').forEach(function(element)
{
element.addEventListener('click', function(e) {
var r = confirm("You clicked like");
if (r == true) {
alert("you clicked OK");
} else {
alert("you clicked Cancel");
e.preventDefault();
}
});
});
For reference : https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault
You could try replacing the original function with a different function of your own.
document.querySelectorAll('a[data-testid="fb-ufi-likelink"]')[0].onclick =
e => console.log('blablabla!')
document.querySelectorAll('a[data-testid="fb-ufi-likelink"]').forEach(function(element) {
let originalOnClick = element.onclick
element.onclick = null
element.addEventListener('click', function(e) {
console.log('look ma, no hands!')
originalOnClick(e)
})
})
Like
I tested it on Facebook and it works there too.
Obviously you have to adapt this concept to your needs.
You can use event.preventDefault()
Just add the parameter to your listener function
function(event){
...
event.preventDefault();
}
Just implemented an alert on my Google Spreadsheet App, it works via browser, but it's not working on the Google mobile app.
Below the code I am using:
function showAlert(currentValue) {
var ui = SpreadsheetApp.getUi();
var result = ui.alert(
'WARNING',
'You are modifying the cell with value ' + currentValue + ', do you want to continue?',
ui.ButtonSet.YES_NO);
// Process the user's response.
if (result == ui.Button.YES) {
// User clicked "Yes".
return true;
} else {
// User clicked "No" or X in the title bar.
return false;
}
}
There's any solution to make it work on mobile app too or any other similar solution to warn the user when trying to modify a not empty cell?
Thanks.
I am making in which I want to display alert box and then redirect it to some other page in asp.net
My code is
var s = Convert.ToInt32(Session["id"].ToString());
var q = (from p in db.students
where p.userid == s
select p.sid).SingleOrDefault();
if (q == 0)
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "reg();", true);
}
this is my reg() function
function reg() {
var con = alert('Please Register Your Self Fisrt ..!! Thank you');
window.location = "reg.aspx";
}
My code is working fine but alert box gets disappear after some second without clicking on it because of that user is unable to read alert message
I want to redirect it to reg.aspx but after clicking OK on alert box ..
please help
Firing a confirm box instead of alert will do what you are trying to achieve. You will have the option to redirect conditionally or unconditionally
function reg(){
var con=confirm("You need to register first before proceeding. Redirect to Registration Page");
if(con==true){
window.location = "reg.aspx";
}
else{
//if redirect unconditionally
window.location = "reg.aspx";
}
}
I need a confirmation box to pop up when a user hits a Save button on my webpage. I currently have a confirm box showing up whenever a user hits ANY button. I need it strictly for the one. The button I need it linked to is called btnsavesurvey.
Here is my current code in the page_load:
Dim message As String = "Do you want to complete survey?"
Dim sb As New System.Text.StringBuilder()
sb.Append("return confirm('")
sb.Append(message)
sb.Append("');")
ClientScript.RegisterOnSubmitStatement(Me.GetType(), "alert", sb.ToString())
$('#btnsavesurvey').click(function(){
var r = confirm("Your message");
if (r == true) {
alert("You pressed OK!");
// Do something when the user pressed ok
} else {
alert("You pressed Cancel!");
// Do something when the user pressed cancel
};
});
If your btns id is btnsavesurvey if its class is btnsavesurvey than use .btnsavesurvey