2010-12-17 61 views
3

我想弄清楚如何讓Dashcode Web應用程序區分iPhone瀏覽器和iPad瀏覽器。一個可行的例子是Apple iPad User Guide。 iPad將顯示一個光滑的代碼編譯界面。 iPhone被重定向到一個網頁。Dashcode區分iPad和iPhone瀏覽器

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

我在編輯redirector.js文件。以下強迫iPad使用由Dashcode而不是Mobile 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"]; 
} 

感謝您的任何建議。

回答

0

我最終最終使用了一些基於this post at ScottRockers blog的代碼。感謝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"]; 
} 
4

測試window.navigator.userAgent。它會將iPad包含在iPod touch上的iPad或iPod上。

var oniPad = /iPad/.test(window.navigator.userAgent); 
+0

嘿。這次真是萬分感謝。我最終最終選擇了一些與衆不同的東西,但是你的回答讓我走上了正軌。我的部分問題是混合了我的Objective-C和Javascript。衛生署! – DenVog 2010-12-17 20:56:38

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"]; 
} 
相關問題