重定向旧浏览器Safari用户

编程入门 行业动态 更新时间:2024-10-25 00:29:51
本文介绍了重定向旧浏览器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 = "www.google" } </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 = "www.google" } } } </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用户

本文发布于:2023-10-31 19:10:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547011.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   浏览器   用户   Safari

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!