The prompt() method is used to display a dialog box with an optional message prompting the user to input some text. It is often used if the user wants to input a value before entering a page. It returns a string containing the text entered by the user, or null.
- message is a string of text to display to the user. It can be omitted if there is nothing to show in the prompt window i.e. it is optional.
- default is a string containing the default value displayed in the text input field. It is also optional.
Before clicking the button:
After clicking the Click me! button:
After pressing the OK button in dialog box:
Supported Browsers: The browser supported by the window prompt() method are listed below:
- Google Chrome 1
- Edge 12
- Internet Explorer 4
- Firefox 1
- Opera 3
- Safari 1