重定向旧浏览器Safari用户 [英] Redirect Old Browers Safari Users
本文介绍了重定向旧浏览器Safari用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此代码重定向野生动物园用户...
i'm using this code to redirect safari users...
<script>
var uagent = navigator.userAgent.toLowerCase();
if(/safari/.test(uagent) && !/chrome/.test(uagent))
{
window.location.href = "http://www.google.com"
}
</script>
但是我需要一个脚本来仅重定向旧的野生动物园浏览器,有人可以帮我吗?
But i need a script to redirect only old safari browsers, someone can please help me?
推荐答案
<script type="text/javascript">
window.onload = function () {
var uagent = navigator.userAgent.toLowerCase();
var safari = uagent.match(/safari\/(\S+)/);
var chrome = uagent.match(/chrome\/(\S+)/);
var MIN_SAFARI_VERSION = 900;
if(safari && !chrome) {
if (parseFloat(safari[1]) < MIN_SAFARI_VERSION) {
window.location.href = "http://www.google.com"
}
}
}
</script>
safari
的值将为 [ safari /(版本号),(版本号)]
,因此 safari [1]
会给您版本号作为字符串。然后,您可以尝试将该值解析为浮点数(或整数)以获取版本号,然后根据结果进行重定向。
The value of safari
will be ["safari/(version number)", "(version number)"]
, so safari[1]
will give you the version number as a string. You can then attempt to parse that value as a float (or int) to get the version number, then redirect based on the result.
这篇关于重定向旧浏览器Safari用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文