Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js window.confirm

// window.confirm(message);
/*
`window.confirm` opens a confirmation dialog with an "Ok"
and "Cancel" button. Upon receiving input, the dialog is
closed and a boolean is returned. `window.confirm` returns
true if the "Ok" button was pressed or false if "Cancel"
was pressed.
*/

const process_something = window.confirm("Are you sure you would like to process something?");
if (process_something) {
	window.alert("Processing something...");
} else {
	window.alert("Operation cancelled.");
}
/*
Note that this will pause code execution until
the dialog receives input. You can't fully get
around this, however using asynchronous
functions or promises, you can get other
statements to be called just after the dialog
is closed and before the dialog returns its
response.
*/
window.confirm = (function() {
	const synchronous_confirm = window.confirm;
	return async function(message) {
		return synchronous_confirm(message);
	};
})();
// OR
window.confirm = (function() {
	const synchronous_confirm = window.confirm;
	return function(message) {
		return new Promise((res, rej) => {
			try {
				res(synchronous_confirm(message));
			} catch (error) {
				rej(error);
			}
		});
	};
})();
Comment

PREVIOUS NEXT
Code Example
Javascript :: removeclass multiple 
Javascript :: json array to string in postgresql 
Javascript :: async in useeffect 
Javascript :: javascript how to check if element is visible on screen 
Javascript :: regex to match string not in between quotes 
Javascript :: react-router-dom navlink active 
Javascript :: regex not contains 
Javascript :: javascript add line from file to array 
Javascript :: get url without parameters javascript 
Javascript :: semantic ui dropdown value react 
Javascript :: vue 3 global variable 
Javascript :: js throw custom error 
Javascript :: check if an array is empty javascript 
Javascript :: Jquery handle change event of file upload created dynamically 
Javascript :: copy to clipboard jquery javascript 
Javascript :: install aos angular 10 
Javascript :: for loop on a array 
Javascript :: iframe content fetching 
Javascript :: javascript get now date yyyy-mm-dd 
Javascript :: get the next character javascript 
Javascript :: nodejs aws s3 bucket delete item 
Javascript :: javascript reverse loop 
Javascript :: add class jquery 
Javascript :: JavaScript Window - The Browser Object Model 
Javascript :: React Hook "React.useState" is called in function "placeItem" which is neither a React function component or a custom React Hook function react-hooks/rules-of-hooks 
Javascript :: generate guard angular 
Javascript :: lodash remove element from list 
Javascript :: $post in jquery 
Javascript :: Select All Elements With A Class getElementsByClassName 
Javascript :: javascript string methods 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =