如果未找到 chrome 18,则重定向 Web 浏览器

Redirect a webbrowser if chrome 18 is not found

我创建此脚本是为了仅在未找到 chrome 18 时隐藏页面,如果 [=21] 我如何确保将 url 重定向到外部页面=] 18 没有找到而不是只隐藏页面? 我想重定向到这个网站 http://search.aol.com/aol/webhome

<div id="hiddenContent" style="display: none;">
My hidden content.
</div>

<script>
function GetChromeVersion() {     
    var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
    return raw ? parseInt(raw[2], 10) : false;
}
if (GetChromeVersion() == 18)
    document.getElementById("hiddenContent").style.display = "";
</script>

有可能,例如通过使用:

window.location.href='http://search.aol.com/aol/webhome';

在你的函数中。但我不会推荐你这个。你永远不应该相信客户端,因为 JavaScript 可以很容易地被更改,并且即使 JavaScript 重定向,如果他们愿意,有人也可以访问你的站点,并且只需付出最小的努力来修改页面源代码。 Javascript 在 client-side 上处理,而 php 完全是 server-side。在这种情况下,我会使用 php 而不是 JavaScript。尝试使用 php 检查它,如果它不是 chrome 18,请使用:header('Location: http://search.aol.com/aol/webhome');

编辑:

<?php function is_chrome() { return(eregi("chrome/18", $_SERVER['HTTP_USER_AGENT'])); }   if(is_chrome()) { header('Location: http://www.search.aol.com/aol/webhome'); } ?> 把它放在文件的顶部,应该可以,但还没有测试过,如果没有,只需将 eregi('chrome/18') 中的字符串更改为您需要的字符串(它是一个正则表达式)