The share is mainly two case, added last the Location of javaScript, the Navigator, the History of actual combat application.

Case 1: URL parameter transfer

Location actual URL parsing, for URL parsing, different requirements, processing is not the same, this case parsing URL transfer parameters, and obtain url transfer parameters:

`

Function queryUrl (url) {var objUrl = {}; Var urlData = url.split('? ') [1]; If (urlData) {var urlArr = urldata.split ('&'); For (var I = 0, len = urlarr.length; i < len; i++) { var curArr = urlArr[i].split('='); ObjUrl [curArr[0]] = curArr[1]} return objUrl}} console.log(queryUrl (url)) // {pageType: "news", pageNum: "1" }Copy the code

The core of this case, is mainly the application of the string split method, through split the URL string split

Case two, verify the browser

In the daily development, and analysis of the current browser environment is very necessary, because we need to do in a different environment or platform of different processing operations, especially in the mobile terminal development, android and ios is more important to verify, because h5 page is running in the browser on the mobile end, so how to validate, please share case code:

`

var browser={ versions:function(){ var u = window.navigator.userAgent; Return {trident: u.iddexof (' trident ') > -1, //IE kernel presto: Opera webKit ('Presto') > -1, // Opera webKit ('AppleWebKit') > -1, // Apple, Google gecko: U.idexof ('Firefox') > -1, // Firefox mobile:!! u.match(/AppleWebKit.*Mobile.*/)||!! U.match (/AppleWebKit/), // Whether for mobile terminal ios:!! u.match(/\(i[^;] +; ( U;) ? CPU + / Mac OS X), / / ios terminal android: u.i ndexOf (' android ') > 1 | | u.i ndexOf (' Linux ') > 1, / / android terminal or uc browser iPhone: U.i ndexOf (' iPhone ') > 1 | | u.i ndexOf (' Mac ') > 1, / / is for the iPhone or android QQ browser device: u.i ndexOf (' the ') > 1, / / for the webApp: U.ndexof ('Safari') == -1,// whether it is a Web application with no header and bottom weixin: u.ndexof ('MicroMessenger') == -1 // whether it is a wechat browser}; }() } console.log(browser.versions.trident, 'IE') // console.log(browser.versions.webKit, 'goole') // console.log(browser.versions.android, 'android') // console.log(browser.versions.gecko, 'Firefox ') // console.log(browser.versions. Mobile,' mobile ') // console.log(browser.versions. IPhone, 'iphone') // console.log(browser.versions.android, 'android') //Copy the code

`

The core idea of this case is to use the string method indexOf to index whether a key character is contained in the browser information and to check whether a character is contained in the string. There are many ways to use this method. For example, the ES6 string method includes().

conclusion

Share the main purpose is to supplement an article on the Location of javaScript, the Navigator, the History of practical application, in order to deep understanding and application. Like the students to help point a thumbs-up, thanks a million.