Home > Software engineering >  How to disable click outside of the confirm function?
How to disable click outside of the confirm function?

Time:12-21

I am trying to disable click outside the confirm message in JS. Is there any simple solution for this issue? If the confirm message show up on mobile, and i click outside of it.. it will dissapear, but i need it to stay as it is.

 if (confirm("Are u sure?")) {
    
 }

I am also using this function in webview. Maybe there is a problem? Anyone have any suggestions?

EDIT: I found the problem is in the webview. I am using AlertDialog builder and i do not calling the function setCanceledOnTouchOutside();

CodePudding user response:

For anybody in the future, who is making jsAlert with builder. You just need to call .setCancelable(false) before .create(); in Android Studio project.

CodePudding user response:

You can use model to disable click outside. You want to set the backdrop value to static. You may also want to set the keyboard property to false because that prevents the modal from being closed

In JS:

$('#myModal').modal({
    backdrop: 'static',
    keyboard: false
})

or in HTML

<div  id="myModal" data-keyboard="false" data-backdrop="static">
  • Related