pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Javascript pastebin - collaborative debugging tool View Help


Posted by DragoN on Sun 19 Oct 08:26
report abuse | download | new post

  1. var browser = 0;
  2. var debug = 0;
  3.  
  4. function checkBrowser()
  5. {
  6.  
  7.         try
  8.         {
  9.                 if(window.XMLHttpRequest)
  10.                 {
  11.                         x=new XMLHttpRequest();
  12.                 }
  13.                 else
  14.                 {
  15.                         x=new ActiveXObject('Microsoft.XMLHTTP');
  16.                 }
  17.                 x.open("GET","about:blank",false);
  18.                 x.send();
  19.         }
  20.         catch(e)
  21.         {
  22.                 if(debug)
  23.                         alert(e + " | " + e.name + " - " + e.message);
  24.                        
  25.                 if(e.message)
  26.                 {
  27.                         switch(e.message)
  28.                         {
  29.                                 case "Access to restricted URI denied":
  30.                                         browser = 3; //Firefox 3.0
  31.                                         break;
  32.                                 case "Security violation":
  33.                                         browser = 4; // Opera 9.5
  34.                                         break;
  35.                                 case "Permission denied":
  36.                                     try
  37.                                     {
  38.                                         if(google) {} // Google Chrome and Safari throws differents error messages
  39.                             }
  40.                             catch(w)
  41.                             {
  42.                                 if(debug)
  43.                                     alert(w + " | " + w.name + " | " + w.message);
  44.                                
  45.                                 if(w.message.length > 1)
  46.                                     browser = 5;
  47.                                 else
  48.                                     browser = 7;
  49.                             }
  50.                             finally
  51.                             {
  52.                                 break;
  53.                             }
  54.                                 default:
  55.                                         break;
  56.                         }
  57.                 }
  58.                 else
  59.                 {
  60.                         if(e == "Permission denied to call method XMLHttpRequest.open")
  61.                         {
  62.                                 browser = 2;
  63.                         }
  64.                 }
  65.                
  66.                
  67.                 /*********************** Internet Explorer *********************************/
  68.                 if(e.number && !e.name.match(/Type/))
  69.                 {
  70.                         browser = 6; // IE 6.0
  71.                 }
  72.                
  73.                 if(e.description.match(/ /) && browser == 0)
  74.                 {
  75.                         browser = 1; // Internet Explorer 7.0+
  76.                 }
  77.                 /**************************************************************************/
  78.         }
  79.         finally
  80.         {
  81.                 showBrowser();
  82.         }
  83. }
  84.  
  85.  
  86. /******************************************
  87. * List of detected brwoser in the AJAX checking *
  88. ******************************************/
  89. function showBrowser()
  90. {
  91.         var msg = "";
  92.         switch(browser)
  93.         {
  94.                 case 1:
  95.                         msg = "Internet Explorer 7.0+";
  96.                         break;
  97.                 case 2:
  98.                         msg = "Mozilla Firefox 2.0";
  99.                         break;
  100.                 case 3:
  101.                         msg = "Mozilla Firefox 3.0";
  102.                         break;
  103.                 case 4:
  104.                         msg = "Opera 9.5";
  105.                         break
  106.                 case 5:
  107.                         msg = "Safari 3";
  108.                         break;
  109.                 case 6:
  110.                         msg = "Internet Explorer 6.0";
  111.                         break;
  112.                 case 7:
  113.                         msg = "Google Chrome";
  114.                         break;
  115.                 default:
  116.                         msg = "Browser version not detected";
  117.         }
  118.         document.getElementById("real").innerHTML = msg;
  119.         document.getElementById("useragent").innerHTML = navigator.userAgent;
  120.         document.getElementById("data").style.backgroundRepeat = "no-repeat";
  121.         document.getElementById("data").style.backgroundPosition = "right";
  122.         document.getElementById("data").style.backgroundImage = "url('saveData.ashx?browser=" + browser + "')";
  123. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me