问题描述
我想将某个年龄的所有浏览器分流到自己的网页。什么是最好的方法这样做?也许在头部中的一些JS包裹在:
< !- [if lte IE 7]
< script type =text / javascript>
window.location =/ unsupported-browser /;
< / script>
<![endif] - >
不应该将浏览器发送到:我有一个基本的控制器和视图来处理它?是这么简单吗?
使用和到该页面。
但更重要的是,为什么不允许IE用户访问您的网站?是由于CSS还是其他问题?
代码:
$ this-> load-> helper('url');
$ this-> load-> library('user_agent');
if($ this-> agent-> browser()=='Internet Explorer'and $ this-> agent-> version()< = 7)
redirect('/ unsupported-browser');
编辑:
如前所述;如果您想在整个网站上执行此操作,请在 MY_Controller 中运行,并确保添加
$ this-> uri-> segment(1)!='unsupported-browser '
作为避免重定向循环的额外条件。I want to shunt all browsers of a certain age off to their own page. What is the best method for doing this? Perhaps some JS in the header that is wrapped in :
<!--[if lte IE 7 ]> <script type="text/javascript"> window.location = "/unsupported-browser/"; </script> <![endif]-->
Shouldn't the above send the browser to: http://example.com/unsupported-browser/ where I have a basic controller and view to handle it? Is it that simple?
解决方案Do this in php instead. Use the user_agent class and redirect to that page.
But more importantly, why don't you allow IE users access to your site? Is it due to CSS or something else?
Code:
$this->load->helper('url'); $this->load->library('user_agent'); if ($this->agent->browser() == 'Internet Explorer' and $this->agent->version() <= 7) redirect('/unsupported-browser');
Edit:
As mentioned; if you want this over your entire site, run this in MY_Controller and make sure to add
$this->uri->segment(1) != 'unsupported-browser'
as an extra condition to avoid redirect loops.这篇关于代码Igniter - 检测浏览器的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!