检测浏览器文件兼容性
我正在寻找一种方法来检测用户的网络浏览器可以显示哪些文件(本机或通过插件),无论是 PHP 的服务器端还是 JavaScript 的客户端。基本上,我想要一个显示文件的框( 中的音频、
中的文档等),但是如果浏览器根本无法显示该文件,我想向用户显示错误并给他们一个下载链接。
感谢您的任何帮助。
I am looking for a way to detect what files a users web browser can display (natively or via plugin), either server side in PHP or client side in JavaScript. Basically, I want to have a box in which a file is displayed (audio in an <embed>
, documents in a <frame>
, etc), however if the browser is simply incapable of displaying the file, I want to show the user an error and give them a link to download it.
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最好的选择是确定哪些浏览器受支持,哪些浏览器不受支持,然后使用浏览器检测来确定向客户端发送哪些响应。
Quirksmode 有一个很棒的脚本用于此目的,并且在此页面上有一个演示:
http://www.quirksmode.com quirksmode.org/js/detect.html
Your best bet is going to be to determine what browsers are supported and which ones aren't and then use browser detection to determine what response to send to the client.
Quirksmode has a great script for this purpose as well as a demo on this page:
http://www.quirksmode.org/js/detect.html
如果用户关闭 javascript 会发生什么?
PHP $_SERVER['HTTP_USER_AGENT'] 可以伪造,即使是新手也可以使用用户代理切换器(firefox 插件)来做到这一点
我认为这个问题没有绝对的解决方案。
what happen if user turn off javascript ?
PHP $_SERVER['HTTP_USER_AGENT'] can be faked, even a newbie can do this with User Agent Switcher (a firefox addon)
i think there isn't a absolute solution for this.