I want the user to be directed to my mobile implementation when he tries to load my webpage using a开发者_开发百科 mobile device. Is there any script that I can use for iphone, android and maybe samsung? I found my scripts in the internet but I cannot figure out which one is working and which one is not
If you are wanting a javascript redirect, you can examine the user agent of the browser and act accordingly. This can prove to be inaccurate because user agents can be modified (often times this is the case). The below example checks if the device is an iPad and routes the browser to another location. You will need to find out what user agents you are dealing with for the iPhone, Android, or any other device and implement this logic. Hope this helps.
window.onload = Page_OnLoad;
function Page_OnLoad() {
if (navigator.userAgent.match(/iPad/) != null) {
window.location = "http://[some mobile url]";
}
}
精彩评论