www.webdeveloper.com
Results 1 to 2 of 2

Thread: Redirecting To Mobile Websites

  1. #1
    Join Date
    Jan 2013
    Posts
    1

    Redirecting To Mobile Websites

    I have a seperate page that serves my mobile visitors. Currently I have set up my main page to redirect to the mobile site like this:

    HTML Code:
        <script type="text/javascript">
           <!--
           if (screen.width <= 700) {
           window.location = "http://my-mobile-site.com";
           }
           //-->
        </script>
    This causes screens with less than 700px screens (Mobile Phones and stuff) to redirect to my mobile site and this works.

    HOWEVER...

    I would like to use a Yes/No box or a Ok/cancel box. I have tried doing it like this:

    HTML Code:
    <script type="javascript">
    
    <!--
    if (screen.width <= 700) {
    
    	var answer = confirm("Visit Mobile Site?")
    	if (answer){
    	window.location = "http://my-mobile-site.com";
    	}
    	else {
    	}
    }
    
     -->
    
    </script>
    Only this does not work.

    Any Help or sugestions?

  2. #2
    Join Date
    Nov 2006
    Location
    Oakland
    Posts
    500
    if (screen.width <= 700) {

    var answer = confirm("Visit Mobile Site?"); //you omitted the semi-colon
    if (answer){
    window.location = "http://my-mobile-site.com";
    }
    else {
    }
    }



    You could just write:

    if ((screen.width <= 700) && confirm("Visit Mobile Site?")) {
    window.location = "http://my-mobile-site.com";
    }

    There is no need for the "else" because the user will stay in the current site which caters to larger screen sizes (desktops, laptops, tablets)

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