rivkamak
asked on
Redirecting Mobile Users
What's the best script to use to redirect Mobile users to a specific mobile section of your website?
You may found some useful infos in this article : https://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_2298-ASP-NET-Mobile-Device-Detection-and-Redirection.html
ASKER
How can I do this on an html page using javascript?
<script type="text/javascript">
var agent=navigator.userAgent. toLowerCas e();
var is_iphone = ((agent.indexOf('iphone')! =-1);
if (is_iphone)
{
alert('Iphone Browser');
window.location = 'http://www.google.co.uk';
}
</script>
var agent=navigator.userAgent.
var is_iphone = ((agent.indexOf('iphone')!
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. toLowerCas e();
var is_iphone = (agent.indexOf('iphone')!= -1);
if (is_iphone)
{
alert('Iphone Browser');
window.location = 'http://www.google.co.uk';
}
</script>
<script type="text/javascript">
var agent=navigator.userAgent.
var is_iphone = (agent.indexOf('iphone')!=
if (is_iphone)
{
alert('Iphone Browser');
window.location = 'http://www.google.co.uk';
}
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.t est(naviga tor.userAg ent)
Check this : http://user-agent-string.info/list-of-ua/browser-detail?browser=BlackBerry
Answer : yes
Line 2 : /iphone|ipad|android|blackberry|mini|windows\sce|palm/i.t
Check this : http://user-agent-string.info/list-of-ua/browser-detail?browser=BlackBerry
Answer : yes
If you want to complete : http://user-agent-string.info/list-of-ua#Mobile%20Browser
ASKER
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>
Do you have access to the server? A script will do the trick, but this is better done in other ways in IIS.
ASKER
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/
http://detectmobilebrowser.com/
ASKER
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.
To try it, just rename your current index.html to index.asp and see if it still works.
ASKER
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.
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!
<%
user_agent = request.servervariables("H
%>
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: