2.6 Interaction

히진로그·2022년 1월 25일
0

Modern-Javascript

목록 보기
3/14

출처: https://javascript.info/

  • 혼자 읽고 타이핑하며 이해하면서 공부한 흔적 남기기

alert

shows a message

The mini-window with the message is called a modal window. The word 'modal' means that the visitor can't interact with the rest of the page, press other buttons, etc, until they have dealt with the window.

prompt

shows a message asking the user to input text. It returns the text or, if Cancel button or Esc is clicked, null.

The function prompt accepts two arguments.

result = prompt(title, [default]);

It shows a modal window with a text message, an input field for the visitor, and the buttons OK/Cancel.

*[]: denote that the parameter is optional, not required.

title : The text to show the visitor.

default : An optional second parameter, the initial value for the input field.

The visitor can cancel the input by pressing Cancel or hitting the Esc key, then we get null as the result.

confirm

shows a message and waits for the user to press 'OK' or 'Cancel'. It returns true for OK and false for Cancel/Esc.

result = confirm(question);

All these methods are modal: they pause script execution and don't allow the visitor to interact with the rest of the page until the window has been dismissed.

There are two limitations shared by all the methods above.

  1. The exact location of the modal window is determined by the browser. Usually, it's in the center.
  2. The exact look of the window also depends on the browser. We can't modify it.

0개의 댓글