Created
July 6, 2023 09:31
-
-
Save sreekanthgoud/89a5718f92a69f50be4df2d77aebd2fb to your computer and use it in GitHub Desktop.
Javascript get alertbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Wrap the original window.alert function... | |
| const windowAlert = window.alert; | |
| window.alert = function(message) { | |
| console.log(`window.alert called with message: ${message}`); | |
| return windowAlert(message); | |
| }; | |
| alert('FOO'); | |
| // Console Output: | |
| // window.alert called with message: FOO | |
| // ======================================================== | |
| // Wrap the original window.prompt function... | |
| const windowPrompt = window.prompt; | |
| window.prompt = function(message) { | |
| console.log(`window.prompt called with message: ${message}`); | |
| const input = windowPrompt(message); | |
| console.log(`user entered: ${input}`); | |
| return input; | |
| }; | |
| prompt('BAR'); | |
| // Console Output: | |
| // window.prompt called with message: BAR | |
| // user entered: xxx | |
| // ======================================================== | |
| // Wrap the original window.confirm function... | |
| const windowConfirm = window.confirm; | |
| window.confirm = function(message) { | |
| console.log(`window.confirm called with message: ${message}`); | |
| const choice = windowConfirm(message) ? 'ok' : 'cancel'; | |
| console.log(`user clicked: ${choice}`); | |
| return choice; | |
| }; | |
| confirm('BAZ'); | |
| // Console Output: | |
| // window.confirm called with message: BAZ | |
| // user clicked: ok (or 'cancel' if you click 'cancel') | |
| // reference by https://stackoverflow.com/questions/22578897/how-to-get-text-from-alert-box |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
window.workspace = window.alert;
window.alert = function(msg) {
console.log('Alert message:', msg);
if (msg.toLowerCase().includes('valid')) {
//write code
};
}