Posted By

jink on 11/11/09


Tagged

ajax javascript safari aspnet Microsoft chrome MS webkit


Versions (?)

ASP.net & MS AJAX: Enabling WebKit support (chrome, safari) in MS AJAX (fixing webkit browser detection)


 / Published in: JavaScript
 

URL: http://blogs.prakashinfotech.com/Lists/Posts/Post.aspx?ID=24

Load this Javascript after the MS AJAX files have been loaded. In the example I am using jQuery to call the patchMicrosoftAjax() method, but you can use any method you desire.

  1. (function() {
  2. /* patch MS AJAX to support webkit browsers */
  3. function patchMicrosoftAjax() {
  4. Sys.Browser = {};
  5. Sys.Browser.InternetExplorer = {};
  6. Sys.Browser.Firefox = {};
  7. Sys.Browser.WebKit = {}; //Safari 3 is considered WebKit
  8. Sys.Browser.Safari = {};
  9. Sys.Browser.Opera = {};
  10. Sys.Browser.agent = null;
  11. Sys.Browser.hasDebuggerStatement = false;
  12. Sys.Browser.name = navigator.appName;
  13. Sys.Browser.version = parseFloat(navigator.appVersion);
  14. if (navigator.userAgent.indexOf(' MSIE ') > -1) {
  15. Sys.Browser.agent = Sys.Browser.InternetExplorer;
  16. Sys.Browser.version = parseFloat(navigator.userAgent.match(/MSIE (\d+\.\d+)/)[1]);
  17. Sys.Browser.hasDebuggerStatement = true;
  18. } else if (navigator.userAgent.indexOf(' Firefox/') > -1) {
  19. Sys.Browser.agent = Sys.Browser.Firefox;
  20. Sys.Browser.version = parseFloat(navigator.userAgent.match(/ Firefox\/(\d+\.\d+)/)[1]);
  21. Sys.Browser.name = 'Firefox';
  22. Sys.Browser.hasDebuggerStatement = true;
  23. } else if (navigator.userAgent.indexOf('WebKit/') > -1) {
  24. Sys.Browser.agent = Sys.Browser.WebKit;
  25. Sys.Browser.version = parseFloat(navigator.userAgent.match(/WebKit\/(\d+(\.\d+)?)/)[1]);
  26. Sys.Browser.name = 'WebKit';
  27. } else if (navigator.userAgent.indexOf(' Safari/') > -1) {
  28. Sys.Browser.agent = Sys.Browser.Safari;
  29. Sys.Browser.version = parseFloat(navigator.userAgent.match(/ Safari\/(\d+(\.\d+)?)/)[1]);
  30. Sys.Browser.name = 'Safari';
  31. } else if (navigator.userAgent.indexOf('Opera/') > -1) {
  32. Sys.Browser.agent = Sys.Browser.Opera;
  33. }
  34. }
  35. if (jQuery) jQuery(patchMicrosoftAjax);
  36. })();

Report this snippet  

You need to login to post a comment.