我有一个脚本,可以检测到安卓设备,然后重定向到"android.html“。在"android.html“页面上,您可以下载应用程序,也可以单击" continue”继续进入"index.html“。问题是当你点击“继续”时,你陷入了一个无限的重定向循环,返回到"android.html.如何让点击“继续”忽略浏览器检测重定向脚本?“
index.html javascript安卓检测重定向
var isAndroid = ua.indexOf("android") > -1;
if(isAndroid) {
window.location = 'android.html';
}android.html
<html>
<head>
</head>
<body>
If you are not using Dolphin Browser HD.</br>
<a href="dbs/js/DolphinbrowserV7.3.1beta.apk">CLICK HERE TO INSTALL</a></br></br>
<a href="index.html">CONTINUE</a>
</body>
</html>发布于 2012-02-04 07:19:02
我不知道您是否可以,但是一种解决方案是在查询字符串中使用a参数,例如:
var isAndroid = ua.indexOf("android") > -1;
var isContinue = window.location.href.split(/ParameterName=/)[1];
if(isAndroid && notContinue) {
window.location = 'android.html';
}然后,在continue按钮中:
<a href="index.html?ParameterName=redirect">CONTINUE</a>请注意,我获取字符串值的方法无论如何都不是错误的,您可以看看this answer
发布于 2012-02-04 07:17:52
在url中添加一些querystring
<html>
<head>
</head>
<body>
If you are not using Dolphin Browser HD.</br>
<a href="dbs/js/DolphinbrowserV7.3.1beta.apk">CLICK HERE TO INSTALL</a></br></br>
<a href="index.html?test=a">CONTINUE</a>
</body>
</html>并在你的javascript中写下逻辑
var url=location.href;
var isValue=url.indexOf('?test=a') // -1 says its not there.
var isAndroid = ua.indexOf("android") > -1;
if(isAndroid && isValue==-1) {
window.location = 'android.html';
}发布于 2012-02-04 07:18:19
var isAndroid = ua.indexOf("android") > -1;
var fromAndroidPage = (location.search.indexOf("fromAndroidPage=yes") != -1);
if(fromAndroidPage && isAndroid) {
window.location = 'android.html';
}将您的页面更改为
<a href="index.html?fromAndroidPage=yes">CONTINUE</a>https://stackoverflow.com/questions/9136737
复制相似问题