Dashcode Distinguish Between iPad and iPhone Browser
-
11-10-2019 - |
Question
I am trying to figure out how to get a Dashcode web application to distinguish between an iPhone browser and iPad browser. A working example of this is the Apple iPad User Guide. An iPad will display a slick dashcode built interface. The iPhone gets redirected to a web page.
I found some help in the Howto force DashCode question.
I am editing the redirector.js file. The following forces the iPad to use the Safari layout built by Dashcode instead of Mobile Safari, which is what I want. When it is browsed to from an iPhone, it returns a file not found error.
// 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"];
}
Thanks for any suggestions.
Solution 2
I ultimately ended up using some code based on this post at ScottRockers blog. Thanks to ughoavgfhw for putting me on the right track.
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"];
}
OTHER TIPS
Test window.navigator.userAgent. It will include iPad on an iPad or iPod on an iPod touch.
var oniPad = /iPad/.test(window.navigator.userAgent);
I modify my redirector.js file and is doing exactly what you want, maybe is not the best way to do that but it is working, here is my code I hope that works for you:
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"];
}