JavaScript dialog box and status bar instructions _ basic knowledge

Source: Internet
Author: User
During normal work, we often use javascript dialogs whether debugging javascript code or page prompts. In addition to creating a browser window that explicitly does not use the status bar, Each browser window has a status bar at the bottom to display specific messages to users. 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", the following program is continued. if you click "cancel", 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. In addition, the Code stops running when a dialog box is displayed. 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.

The Code is as follows:



Foot home


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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.