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