Quelltext der Datei: http://www.michaelster.ch/jsTestFolder/NavigatorCheckjQuery.htm

Dateigrösse: 9.57 kb

[Anzeige ohne Zeilennummern]


1 
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
      
      <title>NavigatorCheckjQuery</title>
    
    <style type="text/css">
      body         { font:bold 14pt verdana,arial,sans-serif; padding:10pt; margin:20pt; color:#000; background:#fff; }
      #bwtype     { font:bold 30pt arial,verdana,sans-serif; margin:20pt 0; padding:3pt 5pt; background:#fff; border:1pt solid #656565; border-radius: 10px; box-shadow: .3em .3em .5em rgba(0, 0, 0, .8); width:90%; }
      h4        { margin: 12pt; }
      a.jquery_bw { position:absolute; top:33%; left:30pt; color:#cc0033; padding:2px 3px; margin-top:20pt; text-decoration:none; letter-spacing:2px; text-shadow:0 0 2pt #333; }
      a.jquery_bw:hover { color:black; }
    </style>
    <!--
    <script src="https://code.jquery.com/jquery-3.0.0.js"></script>
    <script src="https://code.jquery.com/jquery-migrate-3.0.0.js"></script>
    -->
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script src="jQuery/jquery-browser-plugin/dist/jquery.browser.js"></script>
        
<script type="text/javascript">

(function (factory) {
  if (typeof define === 'function' && define.amd) {
    // AMD. Register as an anonymous module
    define(['jquery'], function ($) {
      return factory($);
    });
  } else if (typeof module === 'object' && typeof module.exports === 'object') {
    // Node-like environment
    module.exports = factory(require('jquery'));
  } else {
    // Browser globals
    factory(window.jQuery);
  }
}(function(jQuery) {
  "use strict";
  function uaMatch( ua ) {
    // If an UA is not provided, default to the current browser UA.
    if ( ua === undefined ) {
      ua = window.navigator.userAgent;
    }
    ua = ua.toLowerCase();

    var match = /(edge)\/([\w.]+)/.exec( ua ) ||
        /(opr)[\/]([\w.]+)/.exec( ua ) ||
        /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
        /(version)(applewebkit)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) ||
        /(webkit)[ \/]([\w.]+).*(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) ||
        /(webkit)[ \/]([\w.]+)/.exec( ua ) ||
        /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
        /(msie) ([\w.]+)/.exec( ua ) ||
        ua.indexOf("trident") >= 0 && /(rv)(?::| )([\w.]+)/.exec( ua ) ||
        ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
        [];

    var platform_match = 
        /(ipad)/.exec( ua ) ||
        /(ipod)/.exec( ua ) ||
        /(iphone)/.exec( ua ) ||
        /(kindle)/.exec( ua ) ||
        /(silk)/.exec( ua ) ||
        /(android)/.exec( ua ) ||
        /(windows phone)/.exec( ua ) ||
        /(win)/.exec( ua ) ||
        /(mac)/.exec( ua ) ||
        /(linux)/.exec( ua ) ||
        /(cros)/.exec( ua ) ||
        /(playbook)/.exec( ua ) ||
        /(bb)/.exec( ua ) ||
        /(blackberry)/.exec( ua ) ||
        [];

    var browser = {},
        matched = {
          browser: match[ 5 ] || match[ 3 ] || match[ 1 ] || "",
          version: match[ 2 ] || match[ 4 ] || "0",
          versionNumber: match[ 4 ] || match[ 2 ] || "0",
          platform: platform_match[ 0 ] || ""
        };

    if ( matched.browser ) {
      browser[ matched.browser ] = true;
      browser.version = matched.version;
      browser.versionNumber = parseInt(matched.versionNumber, 10);
    }

    if ( matched.platform ) {
      browser[ matched.platform ] = true;
    }

    // These are all considered mobile platforms, meaning they run a mobile browser
    if ( browser.android || browser.bb || browser.blackberry || browser.ipad || browser.iphone ||
      browser.ipod || browser.kindle || browser.playbook || browser.silk || browser[ "windows phone" ]) {
      browser.mobile = true;
    }

    // These are all considered desktop platforms, meaning they run a desktop browser
    if ( browser.cros || browser.mac || browser.linux || browser.win ) {
      browser.desktop = true;
    }

    // Chrome, Opera 15+ and Safari are webkit based browsers
    if ( browser.chrome || browser.opr || browser.safari ) {
      browser.webkit = true;
    }

    // IE11 has a new token so we will assign it msie to avoid breaking changes
    // IE12 disguises itself as Chrome, but adds a new Edge token.
    if ( browser.rv || browser.edge ) {
      var ie = "msie";

      matched.browser = ie;
      browser[ie] = true;
    }

    // Blackberry browsers are marked as Safari on BlackBerry
    if ( browser.safari && browser.blackberry ) {
      var blackberry = "blackberry";

      matched.browser = blackberry;
      browser[blackberry] = true;
    }

    // Playbook browsers are marked as Safari on Playbook
    if ( browser.safari && browser.playbook ) {
      var playbook = "playbook";

      matched.browser = playbook;
      browser[playbook] = true;
    }

    // BB10 is a newer OS version of BlackBerry
    if ( browser.bb ) {
      var bb = "blackberry";

      matched.browser = bb;
      browser[bb] = true;
    }

    // Opera 15+ are identified as opr
    if ( browser.opr ) {
      var opera = "opera";

      matched.browser = opera;
      browser[opera] = true;
    }

    // Stock Android browsers are marked as Safari on Android.
    if ( browser.safari && browser.android ) {
      var android = "android";

      matched.browser = android;
      browser[android] = true;
    }

    // Kindle browsers are marked as Safari on Kindle
    if ( browser.safari && browser.kindle ) {
      var kindle = "kindle";

      matched.browser = kindle;
      browser[kindle] = true;
    }

     // Kindle Silk browsers are marked as Safari on Kindle
    if ( browser.safari && browser.silk ) {
      var silk = "silk";

      matched.browser = silk;
      browser[silk] = true;
    }

    // Assign the name and platform variable
    browser.name = matched.browser;
    browser.platform = matched.platform;
    return browser;
  }

  // Run the matching process, also assign the function to the returned object
  // for manual, jQuery-free use if desired
  window.jQBrowser = uaMatch( window.navigator.userAgent );
  window.jQBrowser.uaMatch = uaMatch;

  // Only assign to jQuery.browser if jQuery is loaded
  if ( jQuery ) {
    jQuery.browser = window.jQBrowser;
  }

  return window.jQBrowser;
}));


function getBack() 
{  
  if(jQuery.browser.mobile)
  {
    document.getElementById('self').innerHTML = 'Mobile';
  }
  else if (jQuery.browser.desktop)
  {
    document.getElementById('self').innerHTML = 'Desktop';
  }
  else {
    document.getElementById('self').innerHTML = 'undefined';
  }
}

/***********************************************************************/
$(document).ready(function() {
  //
  var div = document.getElementById('bwtype');
      div.style.fontSize = "30pt";
      div.style.background = "#b00";
      div.style.color = "#fff";
      div.innerHTML = '';
  // If the browser type is Mozilla it`s Firefox
  if ($.browser.mozilla && $.browser.version >= "1.8")
  { 
    div.innerHTML += '<h4>You are using Firefox v.'+$.browser.versionNumber+'</h4>';
  }
  // If the web browser type is Opera
  if( $.browser.opera )
  {
    div.innerHTML += '<h4>You are using Opera v.'+$.browser.versionNumber+'</h4>';
  }
  // If the web browser type is Safari
  if( $.browser.safari )
  {
    div.innerHTML += '<h4>You are using Safari v.'+$.browser.versionNumber+'</h4>';
  }
  // If the web browser type is Chrome
  if( $.browser.chrome )
  {
    div.innerHTML += '<h4>You are using Chrome v.'+$.browser.versionNumber+'</h4>';
  }
  // If the web browser type is Internet Explorer
  if ($.browser.msie && $.browser.version <= 6)
  {
    if(document.all && !window.XMLHttpRequest) {
      document.write('You are using IE 6');
    } 
    else if(document.all && !document.compatMode) {
      document.write('You are using IE 5.x');
    } 
    else {
      document.write('You are using MSIE');
    }
  }
  //If the web browser type is Internet Explorer 6 and above
  if ($.browser.msie && $.browser.version > 6)
  {
    if(document.all) {
      document.write('You are using IE 10+');
    } 
    else if(document.all && !window.atob) {
      document.write('You are using IE 9');
    } 
    else if(document.all && !document.addEventListener) {
      document.write('You are using IE 8');
    } 
    else if(document.all && !document.querySelector) {
      document.write('You are using IE 7');
    } 
    else if($.browser.rv) {
      div.innerHTML += '<h4>You are using IE v.'+$.browser.versionNumber+'</h4>';
    } 
    else if($.browser.edge) {
      div.innerHTML += '<h4>You are using IE v.'+$.browser.versionNumber+'</h4>';
    } 
    else {
      document.write('You are using MSIE');
    } 
  }
}); 

/*
IE 10 or older -   document.all <br/> 
IE 9 or older  -   document.all && !window.atob <br/>
IE 8 or older  -   document.all && !document.addEventListener <br/>
IE 7 or older  -   document.all && !document.querySelector <br/>
IE 6 or older  -   document.all && !window.XMLHttpRequest <br/>
IE 5.x         -   document.all && !document.compatMode <br/>
*/
</script>
    
</head>

<body>
    
<h2 id="self" onclick="getBack();">Desktop or Mobile Device? onClick here:</h2>

<div id="bwtype"></div>

<a class="jquery_bw" href="http://www.michaelster.ch/jsTestFolder/jQuery/jquery-browser-plugin/test/">jQuery Browser Check: see more examples here ...</a>

</body>
</html>