3

我试图弄清楚如何让 Dashcode Web 应用程序区分 iPhone 浏览器和 iPad 浏览器。Apple iPad 用户指南就是一个工作示例。iPad 将显示一个流畅的 dashcode 内置界面。iPhone 被重定向到网页。

我在Howto force DashCode question中找到了一些帮助。

我正在编辑 redirector.js 文件。下面强制 iPad 使用 Dashcode 构建的 Safari 布局,而不是我想要的 Mobile 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"];
}

感谢您的任何建议。

4

3 回答 3

4

测试 window.navigator.userAgent。它将包括 iPad 上的 iPad 或 iPod touch 上的 iPod。

var oniPad = /iPad/.test(window.navigator.userAgent);
于 2010-12-17T20:05:57.533 回答
0

我修改了我的 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"];
}
于 2011-02-01T17:10:47.160 回答
0

我最终根据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"];
}
于 2010-12-17T20:59:10.100 回答