How to send webkit user agents to one site version and all the rest to another?
I am a humble graphic designer who is trying his best to learn development. I have a challenging question that I need some very clear and straightforward help with. From my research it seems that my solution can be accomplished with PHP or Javascript. I am totally an infant in both languages but I don't care which one is used. Preferably whatever is easiest for a noob like me.
So her is the deal…
I have a site I have just put together with a bunch of nice -webkit-transforms http://www.eameswords.com I want to send desktop Safari/Chrome to this site. I want to send iPad and iPhone to a separate touch enabled version too.
The kicker…
I have an Adobe flash version of the site as well. It does all the same interactivity. I want to send user agents for IE, Firefox and Opera to this version.
So I have 3 versions of my site!!
I would like to put all 开发者_运维百科three versions of my site in three separate folders for organizational purposes.
So I need three types of user agent detection and three redirects:
iPad & iPhone (mobile Safari) ––––> folder01
Webkit Browsers (Safari/Chrome) ———> folder02 All other browsers (IE, Firefox, etc.) ————> folder03This is crazy but I need some serious help to make this work. If anyone can give me a straightforward answer I would be happy to swap any of my design skills to pay-it-back. I say this because I need someone to literally write out the solution so I can process it, learn from it. I am really bad at piecing code together.
Thank you so much in advance!!!
Check the user-agent header for the signature.
For example, in PHP:
$user_agent = $_SERVER["HTTP_USER_AGENT"];
//Condition checks: Does $user_agent equal the signature of a webkit browser?
//If not, redirect: header("Location: main.php?nonwebkit=true");
Search for the existence of "webkit" in the User agent string. If it exists, fine. Otherwise, redirect the user to the flash page.
jquery solution:
$(document).ready(function() {
if(navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)){
window.location.replace("URL1");
}
else if ($.browser.webkit){
window.location.replace("URL2");
}
else{
window.location.replace("URL3");
}
});
精彩评论