Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Nov 2012
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts

    detecting mobile users poup windows does not work

    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!

    Code:
        <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>

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,316
    Thanks
    23
    Thanked 613 Times in 612 Posts
    You want a mobile viewer to have a smooth transition to the smaller screen and less bits to download. Loading the page twice and asking questions you know the answer to does not help. And as a side question, how many mobile users do you think would rather stay with a non-responsive 1060pixel width page then one designed for them?

    IMHO, I say just 'do it already.'. Use media querys to send that correct page to all users at the start.

    FYI:
    You call jquery three times,
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    That's the one you want.
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
    Replace it with one that's really old.
    and then
    <script type="text/javascript"
    src="http://code.jquery.com/jquery-1.7.2.js"></script>
    A compromise?
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,374
    Thanks
    11
    Thanked 592 Times in 572 Posts
    different URLs for mobile is so five years ago; build your site correctly and it works and looks great for everyone. Allowed exceptions are where a mobile user would want a vastly different purpose from the page than a desktop user, or on information-heavy sites like wikipedia where all the content doesn't fit on mobile and over-loading is wasteful.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    I agree with sunfighter and rnd_me but to answer your question, why don't you do the redirect in PHP using the $_SERVER['HTTP_USER_AGENT']?

    Btw, take note that even if you redirect to the mobile site, the desktop site may still be viewed in mobile by checking the "Request desktop site" option in the browser.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    What do you expect to happen when someone visits using a desktop computer with their useragent set to:

    mozilla mini chrome opera blackberry msie 9999 - eat at joes for the best pizza on earth http://www.joespizza.com

    or whatever else they decide to set that user enterable field to.

    If you are going to test for devices with small screen sizes to display the page differently for them then use CSS to test the screen size directly.
    Last edited by felgall; 02-14-2014 at 08:49 AM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,374
    Thanks
    11
    Thanked 592 Times in 572 Posts
    Quote Originally Posted by felgall View Post
    What do you expect to happen when someone visits using a desktop computer with their useragent set to:

    mozilla mini chrome opera blackberry msie 9999 - eat at joes for the best pizza on earth http://www.joespizza.com

    or whatever else they decide to set that user enterable field to.
    i wish it would say something like "hey dumb@$$, why did you break your browser?"...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #7
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by rnd me View Post
    i wish it would say something like "hey dumb@$$, why did you break your browser?"...
    You can set the useragent to that value if you like. It will only be stupid sites that break as a result - and it will be their fault their site is broken for using the wrong code.

    Alternatively you could just give those sites the value they test for with that message added as well.

    Decent browsers allow you to set the useragent separately for each web site.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #8
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,374
    Thanks
    11
    Thanked 592 Times in 572 Posts
    Quote Originally Posted by felgall View Post
    You can set the useragent to that value if you like. It will only be stupid sites that break as a result - and it will be their fault their site is broken for using the wrong code.

    Alternatively you could just give those sites the value they test for with that message added as well.

    Decent browsers allow you to set the useragent separately for each web site.
    I think we can all agree that it shouldn't be used to serve a radically different set of HTML to IE than to firefox.

    but what you're talking about is how it was a long time ago. The ony browsers that would need to spoof userAgents are unpopular ones that developers don't bother to target. The only browsers pushing this switching capability are developer-focused browsers that offer it as a way to see what the page html looks likes as served to a different browser, for preview and debugging. If that was only a feature that affected "stupid sites", why would "Decent browsers" offer the feature?


    the meaning of the user-agent header was revised about a year ago in HTTP, which is what good browsers use.
    this is probably news to a lot of people, but it's important to understand the what and why of the definition change. It's basically to discourage irrelevant user-agent data, killing "mozilla" and the like.
    see https://hacks.mozilla.org/2013/09/us...and-checklist/ for info and good advice

    changes aside, it's easier than ever not to have to use userAgent, like in css customization for responsive design for example.

    Still, most major sites, not just stupid ones but top-500 sites like google, amazon, facebook, all use user agent to enhance the UX for known devices and browsers.

    User-agent is not good for unknown devices, but it's great for popular old and existing devices. As long as your server provides a decent default, i see nothing wrong with, for example, patching iPhone3 CSS quirks using a customized CSS reset that media queries alone cannot detect.

    I also think that if "obile" appears, you can safely assume it wants a non-hover, non-mouse set of CSS. That's not 100% certain by any means, nothing on the web is, but it can make the UX better for the vast majority of folks who don't even know what a user-agent is.

    good builders understand the set of available tools and the advantages, limitations, and gotchas of each one. Most sites that follow every single spec and guideline are quite unappealing. There's a reason why top sites cheat and it has a lot more to do with what's good for users than what's good for developers.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #9
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by rnd me View Post
    The ony browsers that would need to spoof userAgents are unpopular ones that developers don't bother to target.
    No the only browser that doesn't spoof the useragent by default is Netscape - which identifies itself as Mozilla followed by the version number.

    Every other browser since then has included that value in the useragent in order to pretend to be Netscape and so is spoofing the useragent by default.

    If browsers didn't spoof that they are other browsers then the useragent would only contain the official browser name and the version number (and the actual operating system).

    For example if Chrome 32 were not pretending to be Netscape 5 then the useragent would be

    Chrome 32 Win7

    and not

    Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36

    which is spoofing Netscape (the Mozilla/5.0 part) and at least four other browsers.

    If people didn't misuse the useragent field then there would be no need to spoof the value at all.

    All use of the field except for capturing statistics or for uniquely tagging YOUR browser so it can be distinguished from the billions of others is misusing it.

    If you take your copy of Chrome 32 and replace the default spoofing useragent with one that simply reads Chrome 32 then you would not be spoofing the useragent in that browser. Of course all of the web pages that misuse the useragent to check that the browser is Netscape and refuse to run in any other browser will then refuse to work.
    Last edited by felgall; 02-14-2014 at 11:33 PM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #10
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,374
    Thanks
    11
    Thanked 592 Times in 572 Posts
    Quote Originally Posted by felgall View Post
    No the only browser that doesn't spoof the useragent by default is Netscape - which identifies itself as Mozilla followed by the version number.

    Every other browser since then has included that value in the useragent in order to pretend to be Netscape and so is spoofing the useragent by default.
    i was talking about garbage like ancient versions of opera that let you pretend to be IE by spoofing the whole userAgent string, not just common tokens... As browser capabilities homogenized, there's no longer a need to pretend to be IE. Whole-string spoofing now is pretty much only done for developers by developers, as in the Chrome devtools device emulation feature.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #11
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by rnd me View Post
    i was talking about garbage like ancient versions of opera that let you pretend to be IE by spoofing the whole userAgent string, not just common tokens... As browser capabilities homogenized, there's no longer a need to pretend to be IE. Whole-string spoofing now is pretty much only done for developers by developers, as in the Chrome devtools device emulation feature.
    So why is there still a need for all browsers to spoof that they are Netscape - a browser that has been dead for about 10 years.

    Anyway just about all modern browsers will allow you to set whatever you want as the entire useragent so if you want Internet Explorer, Chrome, Firefox and Opera to all report themselves as eat joe's excellent pizza then you can.

    Setting your own unique useragent to be able to track your own browser usage in your site logs is what the useragent is for so setting it to some unique value that no one else is using is the best way to use it correctly.

    Of course doing so will still break sites that mistakenly believe that it has some other purpose but since most modern browsers also allow you to set the useragent on a site by site basis you can easily give each site the useragent it prefers regardless of whether you are using the browser they want you to use or not. For example I still prefer Opera 12 to more recent versions as there are still many features of 12 yet to be replicated in 19, as a result Google+ used to give a message saying that my browser wasn't supported so I changed the useragent that the browser reports when visiting Google+ to report that I am using Chrome 99. It seems much happier that I am using a version of a browser from the future than a more powerful one from the past.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •