【发布时间】:2014-02-17 07:27:48
【问题描述】:
我正在运行一个集成了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>
然后是下面的代码(在<body>):
<script>
Browsers = new WhichBrowser();
alert("You are using " + Browsers);
</script>
我在easyPHP上运行,考虑到.htaccess,所以.js由PHP解释器解析。
在运行页面时(当然是从服务器),我在Browsers = new WhichBrowser(); 行收到以下错误:“未定义哪个浏览器”。
我做错了什么?
【问题讨论】:
-
不知道,但您永远不需要知道用户正在运行什么浏览器。几乎唯一没问题的情况是对 jsperf 之类的网站进行基准测试...
-
有 javascript 文件 (detect.js) 由运行底部 sn-p 时加载的代码的 sn-p 加载?
-
@NiettheDarkAbsol:当您没有时间和资源来测试所有浏览器和/或为所有现有浏览器调整 CSS ?
-
@PatrickEvans:我想是的...我将如何测试它,如果没有加载,我该如何等待它被加载?
-
@Oliver 不,但我只是按照标准编码,它似乎在所有主要浏览器中都可以正常工作。除了 Firefox,但即使是那个也进展缓慢。
标签: javascript php html .htaccess browser-detection