DashCode区分iPad和iPhone浏览器
-
11-10-2019 - |
题
我正在尝试弄清楚如何获取DashCode Web应用程序以区分iPhone浏览器和iPad浏览器。一个工作的例子是 Apple iPad用户指南. 。 iPad将显示一个光滑的仪表板构建的接口。 iPhone被重定向到网页。
我在 Howto强制仪表盘问题.
我正在编辑redirector.js文件。以下迫使iPad使用DashCode构建的Safari布局,而不是移动Safari,这是我想要的。当它从iPhone浏览时,它将返回未找到错误的文件。
// redirect to the more appropriate product
if (DCProductURLs["mobileweb"] && DCshowiPhone) {
// Changed case so that the Safari layout is displayed on iPad
// window.location.href = DCProductURLs["mobileweb"];
window.location.href = DCProductURLs["desktop"];
}
感谢您的建议。
解决方案 2
我最终最终使用了一些基于的代码 这篇文章在Scottrockers博客. 。感谢ughoavgfhw使我走上了正确的轨道。
if ((navigator.userAgent.indexOf('iPad') != -1)) {
window.location.href = DCProductURLs["desktop"];
}
if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1)) {
window.location.href = DCProductURLs["mobileweb"];
}
其他提示
test window.navigator.useragent。它将在iPad上包含iPad或iPod touch上的iPod。
var oniPad = /iPad/.test(window.navigator.userAgent);
我修改了我的redirector.js文件,并且正在做您想要的事情,也许不是最好的方法,但它可以正常工作,这是我希望对您有用的代码:
var DCProductURLs = {
"mobileweb": "../mobile",
"desktop": "../safari"
};
var DCshowiPhone = RegExp(" AppleWebKit/").test(navigator.userAgent) && RegExp(" Mobile/").test(navigator.userAgent);
var DCqs = window.location.search.substring(1);
if ((DCshowiPhone && DCqs.length > 0)||screen.width>1000) {
var components = DCqs.split("&");
for (var f = 0; f < components.length; f++) {
if (components[f] == "p=desktop") {
DCshowiPhone = false;
break;
}
}
}
// redirect to the more appropriate product
//var device=
if (DCProductURLs["mobileweb"] && DCshowiPhone && screen.width<=960) {
window.location.href = DCProductURLs["mobileweb"];
}
不隶属于 StackOverflow