简体   繁体   中英

I need to show error when user presses escape on prompt box , but code below doesnt seem to work, any answers?

function(catchError) {
    try {

       var firstname = prompt("please enter your first name");

}

    catch (error) {

       alert(error.message);

}} 

1. how can I remove this problem

2 also make this work in google chrome

prompt will return null if cancel or the escape key is pressed. Just check for it:

var firstname = prompt("please enter your first name");
if(firstname !== null) {

} else {
    // ESC or cancel pressed
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM