: How to redirect user into mobile website? Hi how to redirect the user into mobile site when the user accessing from mobile. Say example i have site called www.mysite.com. Now, a person accessing
Hi how to redirect the user into mobile site when the user accessing from mobile. Say example i have site called mysite.com. Now, a person accessing a website from mobile it should redirect to mysite.com/mobile or m.mysite.com.
I put some research in google that we can redirect using javascript to get the user agent(browser)
if(mobile browser) {
//redirect to mysite.com/mobile } else if(normal browser) {
//redirect to mysite.com }
or using screen resolution
if(screen resolution < 800 ) {
//redirect to mysite.com/mobile } else if(screen resolution > 800) {
//redirect to mysite.com }
I think It will not work If it is the case of javascript disable.
Can we do this using .htaccess or php stuff?
Is there any standard mechanism to do this?
More posts by @Sarah324
1 Comments
Sorted by latest first Latest Oldest Best
use media queries for css
in you css put
@media all and (max-device-width: 1024px) {
... css here
}
the max-device-width should be the width of the mobile device you want to detect.
on the other hand u can use useragent
in javascript
var isMobile = navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry)/);
if(isMobile) {
// User-Agent is IPhone, IPod, IPad, Android or BlackBerry
}
to check the specific user-agent string
if(navigator.userAgent.match(/iPhone/)) {
// The User-Agent is iPhone
}
in php this is hwo you do this
if(isset($_SERVER['HTTP_USER_AGENT'])){
$agent = $_SERVER['HTTP_USER_AGENT'];
}
check first the useragent of the device
the give the condition
if(preg_match('/^Mozilla/.*?Gecko/i',$agent)){
print "Firefox user.";
// process here for firefox browser
}
in the pregmatch.. you can put into condition 'iPhone','Andriod' etc
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.