Today, we will briefly introduce the Javascript dialog box and status bar.
JavaScript and dialog box:
-
- Three dialog box icons:
In the client browser, three common window methods are used to pop up a simple dialog box, which are alert (), confirm (), and prompt (). Alert () is used to display messages to users. Confirm () requires the user to click OK or cancel. Prompt () requires the user to input a string. The three images below are alert (), confirm () and prompt () respectively ().
Alert () dialog box prompt
Confirm () dialog box prompt
Prompt in the prompt () dialog box
-
- Three kinds of dialog box introduction:
The Alert () method pop-up dialog box only displays the prompt information, which serves as a reminder for users.
The confirm () method is used to ask the user for confirmation. Two buttons are displayed: Confirm and cancel. It is equivalent to the IF/else structure. If you click OK, continue to execute the followingProgramIf you click the cancel button, false is returned.
The prompt () method has an input box, and the returned content is the content entered by the user in the input box. The purpose is to obtain user input.
- Introduction to the blocking process in the dialog box:
Both confirm () and prompt () will cause blocking, that is, they will not be returned until the user closes the displayed dialog box. It also means that when a dialog box is displayed,CodeWill stop running. If the document is currently being loaded, it will also stop loading until the user responds with the required input. There is no way to prevent these methods from being blocked, because their return values are user input, so they must wait for the user to input before returning.
In most browsers, alert () also blocks and waits for the user to close the dialog box. However, the alert () method does not block Some browsers (especially netscape3 and 4 on UNIX platforms. However, the tests on fedora11 will also cause blocking. Of course, I didn't use the Netscape test. I used the Firefox browser to test it and it is also blocked. But the rhino author said:
In practice, this small incompatibility rarely causes problems.
Usage of alert (), confirm () and prompt:
Alert ('this is an alert prompt, do you understand? ');
Confirm ('This is a confirm prompt. Are you willing to read it or not? ');
Prompt ('Come, handsome guy, tell your brother your name ');
JavaScript and status bar:
When you place the cursor over a hyperlink, the browser displays the URL address pointed to by the hyperlink on the status bar. However, sometimes you will find that when you place your mouse over a hyperlink or image, some text rather than link addresses are displayed on the status bar.
In JavaScript, the content on the browser's status bar is controlled by two properties of the window object, namely status and defaultstatus. Therefore, you can use JavaScript to change the default behavior of the status bar and display the information we want to display to users.
The attribute status is used to store instantaneous messages, that is, the status bar information is changed only when a trigger event occurs. The defaultstatus attribute specifies the default text displayed in the status bar. Only when a trigger event occurs will the text above the status bar be replaced by the specified status. Otherwise, the content specified by the defaultstatus attribute will be displayed all the time.Copy codeThe Code is as follows: <! --
When you place the cursor over the code, the status bar displays the content displayed in the status bar.
-->
<A href = 'HTTP: // www.jb51.net' target = '_ blank' onmouseover = "window. Status = 'move the cursor over the link and the content displayed in the status bar. '; Return true; "> foot home </a>
In the above example, the event handler must return true; this notifies the browser that when an event occurs, it should not execute its own default action, that is, it should not display the URL of the link in the status bar, if return true is forgotten, the browser overwrites all information displayed by the handler in the status bar with its own URL.
Let's take a look at the defaultstatus example. Set the default value of the page status bar to: Welcome to this site. Thank you for coming.
Defaultstatus = 'Welcome to this site. Thank you for coming ';
Window. defaultstatus = defaultstatus;
Code demo and description:
Sometimes, you may not be able to see the information displayed on the status bar. The following describes how to help you:
In Firefox:
1. Go to tools> options
2. Click the content Tab
3. Ensure that the Javascript option is checked
4. Click Advanced (next to the enable Javascript option)
5. Check the change status bar text Option
6. Click OK to save this screen
7. Click OK again
In Internet Explorer:
1. Go to tools> Internet Options
2. Click the Security Tab
3. Ensure that the Internet option is selected/highlighted
4. Click Custom Level... (This launches the security settings for the Internet zone)
5. Scroll down until you see Allow Status Bar Updates Via Script (under the scripting option). Click Enable
6. Click OK to save this screen
7. Click OK again