JavaScript Window Navigator

Source: Internet
Author: User

1.JavaScript Window Navigator

The Window.navigator object contains information about the visitor's browser.

1.1 Window Navigator

The window.navigator object can be written without using the window prefix.

<div id="Example"></div><script>txt="<p> Browser code:"+ Navigator.appcodename +"</p>"; txt+="<p> Browser Name:"+ Navigator.appname +"</p>"; txt+="<p> Browser version:"+ Navigator.appversion +"</p>"; txt+="<p> Enable cookies:"+ navigator.cookieenabled +"</p>"; txt+="<p> hardware platform:"+ Navigator.platform +"</p>"; txt+="<p> User agent:"+ Navigator.useragent +"</p>"; txt+="<p> User Agent language:"+ Navigator.systemlanguage +"</p>";d Ocument.getelementbyid ("Example"). innerhtml=txt;</script>

1.2 Warning!!!

The information from the Navigator object is misleading and should not be used to detect browser versions because:

    • Navigator data can be changed by browser user
    • Some browsers will identify errors for the test site
    • The browser cannot report a new operating system that is later than the browser published

1.3 Browser detection

Because navigator can mislead browser detection, using object detection can be used to sniff out different browsers.

Because different browsers support different objects, you can use objects to detect the browser. For example, because only opera supports the attribute "Window.opera", you can identify opera accordingly.

Example: if (Window.opera) {... some action ...}

2.JavaScript pop -up window

You can create three message boxes in JavaScript: A warning box, a confirmation box, and a prompt box.

2.1 Warning Box

Warning boxes are often used to ensure that users can get some information.

When the warning box appears, the user needs to click the OK button to continue the operation.

Window.alert ("sometext");

2.2 Confirmation Box

A confirmation box is typically used to verify that a user action is accepted.

When the confirmation card pops up, the user can click "Confirm" or "Cancel" to determine the user action.

When you click "Confirm", the confirmation box returns true and if you click "Cancel", the confirmation box returns false.

Window.confirm ("sometext");

2.3 Hint Box

The prompt box is often used to prompt the user to enter a value before entering the page.

When the prompt box appears, the user needs to enter a value and then click the Confirm or Cancel button to continue the manipulation.

If the user clicks Confirm, then the return value is the value entered. If the user clicks Cancel, the return value is null.

Window.prompt ("sometext","defaultvalue");

2.4 Line break

The pop-up window uses a backslash + "n" to set the line break.

Alert ("hello\nhow is you?") ");

JavaScript Window Navigator

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.