www.webdeveloper.com
Results 1 to 5 of 5

Thread: Need help creating code

Hybrid View

  1. #1
    Join Date
    Nov 2011
    Posts
    2

    Red face Need help creating code

    Hello. Looking to create a script that:

    Detects mobile browser (or mobile phone)
    then produces dialogue (confirm/cancel)box to action re direct to another URL

  2. #2
    Join Date
    Apr 2010
    Location
    Salem,Ma
    Posts
    623
    this looks promising http://localstreamer.posterous.com/j...detect-all-mob


    Code:
     <script type="text/javascript">// <![CDATA[
    &#160;&#160;&#160; var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
    &#160;&#160;&#160; if (mobile) {
    &#160;&#160;&#160; &#160;&#160;&#160; document.location = "http://www.yoursite.com/mobile.html";
    &#160;&#160;&#160; }
    // ]]></script>

  3. #3
    Join Date
    Nov 2011
    Posts
    2

    Talking

    This looks great. Haven't tested it yet. I'm curios as to where the confirm box code is stored ?

    I'll update this as resolved ASAP.

  4. #4
    Join Date
    Apr 2010
    Location
    Salem,Ma
    Posts
    623
    I believe this will suffice. - Just a note, most sites seem to do it automatically these days and provide a link to the main site on the mobile site. Just a thought

    Code:
     <script type="text/javascript">// <![CDATA[
     var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
     if (mobile) {
    var answer = confirm("Would you like to view the mobile version of the site?")
    	if (answer){	
    		document.location = "http://www.yoursite.com/mobile.html";
    	}
    }
    // ]]></script>

  5. #5
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by andycarver View Post
    Hello. Looking to create a script that:

    Detects mobile browser (or mobile phone)
    then produces dialogue (confirm/cancel)box to action re direct to another URL
    Assuming you offer a mobile site for small screen sizes:
    Code:
    <script type="text/javascript"> /* Put on mobile site. Auto-diverts to main if screen width > 500 */
    
    if( screen.width > 500 && !/(\?|\&(amp;)*)useMobile=yes(&|$)/.test( location.search ) )
     location.href = 'myMainSite.htm';
    
    </script>
    
    <!-- On main site -->
    <a href='myMobileSite.htm?useMobile=yes'>Use Mobile-Optimised Site</a>
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles