WhichBrowser集成错误

Oli*_*ver 0 html javascript php .htaccess browser-detection

我正在运行一个集成了WhichBrowser的html页面.

正如README文件中所解释的,我已经在下面的代码中添加了以下代码<head>:

<script>
    (function(){var p=[],w=window,d=document,e=f=0;p.push('ua='+encodeURIComponent(navigator.userAgent));e|=w.ActiveXObject?1:0;e|=w.opera?2:0;e|=w.chrome?4:0;
    e|='getBoxObjectFor' in d || 'mozInnerScreenX' in w?8:0;e|=('WebKitCSSMatrix' in w||'WebKitPoint' in w||'webkitStorageInfo' in w||'webkitURL' in w)?16:0;
    e|=(e&16&&({}.toString).toString().indexOf("\n")===-1)?32:0;p.push('e='+e);f|='sandbox' in d.createElement('iframe')?1:0;f|='WebSocket' in w?2:0;
    f|=w.Worker?4:0;f|=w.applicationCache?8:0;f|=w.history && history.pushState?16:0;f|=d.documentElement.webkitRequestFullScreen?32:0;f|='FileReader' in w?64:0;
    p.push('f='+f);p.push('r='+Math.random().toString(36).substring(7));p.push('w='+screen.width);p.push('h='+screen.height);var s=d.createElement('script');
    s.src='http://localhost/mysite/libs/whichbrowser/detect.js?' + p.join('&');d.getElementsByTagName('head')[0].appendChild(s);})();
</script>
Run Code Online (Sandbox Code Playgroud)

然后是以下代码(在<body>)中:

<script>
Browsers = new WhichBrowser();
alert("You are using " + Browsers);
</script>
Run Code Online (Sandbox Code Playgroud)

我正在运行easyPHP,并考虑.htaccess,因此.js由PHP解释器解析.

当运行页面时(当然是从服务器),我在行上获得以下错误Browsers = new WhichBrowser();:"未定义WhichBrowser".

我做错了什么?

isa*_*isa 8

我有同样的问题并通过执行以下操作修复它:

$(window).on('load', function() {
    Browsers = new WhichBrowser();
    // Put rest of browser detection code here
});
Run Code Online (Sandbox Code Playgroud)

问题是在加载detect.js之前调用脚本.