Js to get browser information and page information

Source: Internet
Author: User

Js to get browser information and page information

1. js gets browser information, including determining whether the browser is mobile or not, browser information, and android version

2. js obtains the url, domain, and title of the page.

 

Function browserInfo () {var browser = {versions: function () {var u = window. navigator. userAgent; // android var num; if (u. indexOf ('think')>-1) {// IEreturn IE;} else if (u. indexOf ('presto ')>-1) {// operareturn Opera;} else if (u. indexOf ('gecko ')>-1 & u. indexOf ('html ') =-1) {// firefoxreturn Firefox;} else if (u. indexOf ('applewebkit '& u. indexOf ('safari ')>-1)>-1) {// Apple, Google kernel if (u. indexO F ('chrome ')>-1) {// chromereturn Chrome;} else if (u. indexOf ('opr') {// webkit Operareturn Opera_webkit} else {// Safarireturn Safari;} else if (u. indexOf ('mobile')>-1) {// if (!! U. match (/(I [^;] +; (U ;)? CPU. + Mac OS X/) {// iosif (u. indexOf ('iphone ')>-1) {// iphonereturn iPhone} else if (u. indexOf ('ipod ')>-1) {// ipodreturn iPod} else if (u. indexOf ('ipad ')>-1) {// ipadreturn iPad} else if (u. indexOf ('android')>-1 | u. indexOf ('linux ')>-1) {// androidnum = u. substr (u. indexOf ('android') + 8, 3); return {type: Android, version: num };} else if (u. indexOf ('bb10')>-1) {// return BB10;} else if (u. indexOf ('iemobile ') {// windows phonereturn Windows Phone }}}// browser version var browserVsersion = browser. versions (); // the current page path var url = window. location. href; // the current page domain name var host = window. location. host; // the current page domain name var host2 = document. domain; alert (host2); // the current page title var title = document. title; // source URL urlvar referer; if (document. referrer. length> 0) {referer = document. referrer;} try {if (referer. length = 0 & opener. location. href. length> 0) {referer = opener. location. href ;}} catch (e) {referer = window. location. href;} // current page source urlreferer = referer. replace ('HTTP ://','');}


 

 

 

 

 

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.