DetectPanda3D.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Based on Apple sample code at
  2. // http://developer.apple.com/internet/webcontent/examples/detectplugins_source.html
  3. // initialize global variables
  4. var detectableWithVB = false;
  5. var pluginFound = false;
  6. function goURL(daURL) {
  7. // Assume we have Javascript 1.1 functionality.
  8. window.location.replace(daURL);
  9. return;
  10. }
  11. function redirectCheck(pluginFound, redirectURL, redirectIfFound) {
  12. // check for redirection
  13. if( redirectURL && ((pluginFound && redirectIfFound) ||
  14. (!pluginFound && !redirectIfFound)) ) {
  15. // go away
  16. goURL(redirectURL);
  17. return pluginFound;
  18. } else {
  19. // stay here and return result of plugin detection
  20. return pluginFound;
  21. }
  22. }
  23. function canDetectPlugins() {
  24. if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
  25. return true;
  26. } else {
  27. return false;
  28. }
  29. }
  30. function detectPanda3D(redirectURL, redirectIfFound) {
  31. pluginFound = detectPlugin('Panda3D');
  32. // if not found, try to detect with VisualBasic
  33. if(!pluginFound && detectableWithVB) {
  34. pluginFound = detectActiveXControl('P3DACTIVEX.P3DActiveXCtrl.1');
  35. }
  36. // check for redirection
  37. return redirectCheck(pluginFound, redirectURL, redirectIfFound);
  38. }
  39. function detectPlugin() {
  40. // allow for multiple checks in a single pass
  41. var daPlugins = detectPlugin.arguments;
  42. // consider pluginFound to be false until proven true
  43. var pluginFound = false;
  44. // if plugins array is there and not fake
  45. if (navigator.plugins && navigator.plugins.length > 0) {
  46. var pluginsArrayLength = navigator.plugins.length;
  47. // for each plugin...
  48. for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
  49. // loop through all desired names and check each against the current plugin name
  50. var numFound = 0;
  51. for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
  52. // if desired plugin name is found in either plugin name or description
  53. if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) ||
  54. (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
  55. // this name was found
  56. numFound++;
  57. }
  58. }
  59. // now that we have checked all the required names against this one plugin,
  60. // if the number we found matches the total number provided then we were successful
  61. if(numFound == daPlugins.length) {
  62. pluginFound = true;
  63. // if we've found the plugin, we can stop looking through at the rest of the plugins
  64. break;
  65. }
  66. }
  67. }
  68. return pluginFound;
  69. } // detectPlugin
  70. // Here we write out the VBScript block for MSIE Windows
  71. if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
  72. document.writeln('<script language="VBscript">');
  73. document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
  74. document.writeln('detectableWithVB = False');
  75. document.writeln('If ScriptEngineMajorVersion >= 2 then');
  76. document.writeln(' detectableWithVB = True');
  77. document.writeln('End If');
  78. document.writeln('\'this next function will detect most plugins');
  79. document.writeln('Function detectActiveXControl(activeXControlName)');
  80. document.writeln(' on error resume next');
  81. document.writeln(' detectActiveXControl = False');
  82. document.writeln(' If detectableWithVB Then');
  83. document.writeln(' detectActiveXControl = IsObject(CreateObject(activeXControlName))');
  84. document.writeln(' End If');
  85. document.writeln('End Function');
  86. document.writeln('</script>');
  87. }