Link to home
Start Free TrialLog in
Avatar of rivkamak
rivkamakFlag for United States of America

asked on

Redirecting Mobile Users

What's the best script to use to redirect Mobile users to a specific mobile section of your website?
Avatar of Gary_Mather
Gary_Mather

You would first need to find the browser agent by gettign the variable:
<%
user_agent = request.servervariables("HTTP_USER_AGENT")
%>

Then you could use a case statement to Response.Redirect to another page/site
A list of user agents are here: http://www.user-agents.org/

You are probably best coding for the well known ones, IE, FF, Chrome etc and redirecting on others by default:
Avatar of leakim971
Avatar of rivkamak

ASKER

How can I do this on an html page using javascript?
<script type="text/javascript">
var agent=navigator.userAgent.toLowerCase();
var is_iphone = ((agent.indexOf('iphone')!=-1);
if (is_iphone)
{
alert('Iphone Browser');
window.location = 'http://www.google.co.uk';
}
</script>
Sorry, extra bracket typo

<script type="text/javascript">
var agent=navigator.userAgent.toLowerCase();
var is_iphone = (agent.indexOf('iphone')!=-1);
if (is_iphone)
{
alert('Iphone Browser');
window.location = 'http://www.google.co.uk';
}
</script>
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Would the javascript be picked up by blackberries and the like?
>http://user-agent-string.info/list-of-ua/browser-detail?browser=BlackBerry

Line 2 : /iphone|ipad|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent)
Check this : http://user-agent-string.info/list-of-ua/browser-detail?browser=BlackBerry

Answer : yes
But the blackberry isn't working on the script.
Then check as User Agent with and post it here

<script language="javascript">
	var is_mobile = (/iphone|ipad|andoid|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent));
	if(is_mobile) window.location = 'http://www.google.co.uk';
        else alert(navigator.userAgent); 
</script>

Open in new window

Do you have access to the server?  A script will do the trick, but this is better done in other ways in IIS.
i can't change my index page to an ASP page, but if it's something I can do in IIS, I can do it.
I was thinking more along the lines of an ISAPI Rewrite rule, but came across this page which has a brilliant little script for ASP.

http://detectmobilebrowser.com/

How do I put ASP script on my index.html page?
Are you sure?  By default IIS will pick up an asp file if you name it INDEX.ASP and there is no INDEX.HTML file in the folder.

To try it, just rename your current index.html to index.asp and see if it still works.

that homepage has all our links and pay per click ads going to it. my web designers will not allow me to change the page name. gotta work around it.
Here is your problem -

HTML is not a dynamic language.  You can't script with it.  It merely takes items in tags ( <tag name> ) and places them on the screen.  Thats where its capabilities end.

You need to use a script to get any functionality out of your page.  Unless you can switch your page to ASP or another scripting language, you can't do what you want with that page at all.

Also, your designers must be idiots if they are linking anything directly to your index.html file.  They should be linking to the root of your website which would be http://www.YourDomain.com.  If they are hard coding links to http://www.YourDomain.com/index.html they complete imbeciles and should be sacked!  I could go through a long list of issues this causes, but I don't want to go off topic on this sure.
Thanks for the points!