Jump to content

how to detect a mobile browser


gwolff2005

Recommended Posts

Hi guys, I need your help, I am very desperate.

I want people visitng my site with a mobile browser seeing a window saying, would you liek to switch to mobile view? - and the redirect.

 

I found this code and I tried to implement it in my php fiel but nothing changes.

Mobile borwser goes immediately to mobile view without window asking first,

*
What am I missing or doing wrong. you can test it out on guntmarwolffdotcom

 

Thanks for your help!

    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <?php
if(isset($_GET['mVar'])){
    session_start();
    $_SESSION['views']=1; // Declaring a session to track the visits
}


if(!$_SESSION['views'] == 1){ // Checking the session and doing the redirection
    if ($_SERVER["QUERY_STRING"] == null){
        echo "
        <script type=\"text/javascript\">
        if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
            window.location.replace('http://m.guntmarwolff.com');}
        </script>
                ";
    }
}
?>  
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.7.2.js"></script>

<!-- Add fancyBox main JS and CSS files -->
<script type="text/javascript"
src="http://www.guntmarwolff.com/fancyapps-fancyBox-v2.1.5-0-ge2248f4/source/jquery.fancybox.js"></script>
<link rel="stylesheet" type="text/css"
href="http://www.guntmarwolff.com/fancyapps-fancyBox-v2.1.5-0-ge2248f4/source/jquery.fancybox.css"
media="screen" />
<script type="text/javascript"     
    jQuery(document).ready(function () {
    jQuery.fancybox({
            'width': '75%', //Use percentage to maintain responsiveness
            'height': '75%',
            'autoScale': true,
            'transitionIn': 'fade',
            'transitionOut': 'fade',
            'type': 'iframe',
            'href': 'popupbox.htm'
     });
    }); </script>
Link to comment
Share on other sites

if(preg_match("/chrome/",strtolower($_SERVER['HTTP_USER_AGENT'])))
{
//use a different css maybe
}
elseif(preg_match("/msie/",strtolower($_SERVER['HTTP_USER_AGENT'])))
{
//use a different css maybe
}
elseif(preg_match("/opera/",strtolower($_SERVER['HTTP_USER_AGENT'])))
{
//use a different css maybe
}
elseif(preg_match("/firefox/",strtolower($_SERVER['HTTP_USER_AGENT'])))
{
//use a different css maybe
}
elseif(preg_match("/safari/",strtolower($_SERVER['HTTP_USER_AGENT'])))
{
//use a different css maybe
}

then add some if statements

 

 

Link to comment
Share on other sites


<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<?php
if(isset($_GET['mVar'])){
session_start();
$_SESSION['views']=1; // Declaring a session to track the visits
}
else
{
session_start();
$_SESSION['views']=0;
}


if(!$_SESSION['views'] == 1){ // Checking the session and doing the redirection
if ($_SERVER["QUERY_STRING"] == null){
echo "
<script type=\"text/javascript\">
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
window.location.replace('http://m.guntmarwolff.com');}
</script>
";
}
}
?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.7.2.js"></script>

<!-- Add fancyBox main JS and CSS files -->
<script type="text/javascript"
src="http://www.guntmarwolff.com/fancyapps-fancyBox-v2.1.5-0-ge2248f4/source/jquery.fancybox.js"></script>
<link rel="stylesheet" type="text/css"
href="http://www.guntmarwolff.com/fancyapps-fancyBox-v2.1.5-0-ge2248f4/source/jquery.fancybox.css"
media="screen" />
<script >
jQuery(document).ready(function () {
jQuery.fancybox({
'width': '75%', //Use percentage to maintain responsiveness
'height': '75%',
'autoScale': true,
'transitionIn': 'fade',
'transitionOut': 'fade',
'type': 'iframe',
'href': 'popupbox.htm'
});
}); </script>

 

Edited by Mancent
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.