Javascript prompt() - cancel button to terminate the function

后端 未结 5 1117
自闭症患者
自闭症患者 2020-12-14 06:19

I\'m calling a Javascript window.prompt() and prompting the user to submit a variable which I compare to another variable (a very basic password protection). Th

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-14 06:36

    One substantial problem with handling the result of 'prompt' is that Safari (at least version 9.1.2) returns "" instead of null when "Cancel" is clicked. This means that: if(result==null) return; does not work, and you cannot distinguish between entry of a null string, and cancellation.

提交回复
热议问题