View Full Version : ASP And My Mobile Website
03-24-2010, 11:39 AM
Thank you for your time everyone. This is an ASP question related to a mobile website I am creating for a client.
I found a pretty decent ASP script that will detect if a user is browsing with a mobile device or not. So far the script is pretty decent and is working just fine. I've tested on three mobile devices and am quite satisfied.
Now my problem is that I don't want to paste that mobile device detection script into the header of every page on the site. I would rather simply make a call to the script and of course have the script perform as it should depending on the browser that's being used.
Can anyone help me figure out the right way to make a call to that detection script and then take the appropriate actions thereafter.
You'll notice in the script these lines at the end:
If mobile_browser>0 Then
End IfI've tried including the script with:
<!--#include file="mobi.asp"-->but that threw a server error. I thought at least it would output whether or not the browser was a mobile browser or not and proceed with rendering the remaining of the page.
It didn't. It worked stand-alone though. My preference is to have the code stay in my mobi.asp file and called within the header of each page.
Any help is greatly appreciated.
Thank you for your time.
03-24-2010, 01:49 PM
OK thus far, I've decided I'm going to create a function that calls the script (I think) and returns either a 0 or 1 based on the user-agent - (mobile or not mobile browser).
If the asp function returns a 0 the user-agent is not mobile and if it returns a 1 then it will be a mobile browser - mobile user-agent.
I shall return to let you know how this pans out. Again, the code pretty much works as is but throwing the whole block into each header section of each page on the site seems a little hefty.
03-24-2010, 03:42 PM
I failed to notice at the bottom of the link I posted regarding the detection of mobile browsers, there was a sentence that says:
"Note that this script uses Option Explicit. If you want to use this script with code that does not use Option Explicit, you should comment out the first two lines to avoid compilation errors."
So I removed the following from the script:
Dim user_agent, mobile_browser, Regex, match, mobile_agents, mobile_ua, i, size
...added the following into the head of the home page:
<!--#include file="mobi.asp" -->
...and edited the last block of code to read:
If mobile_browser>0 Then
...re-tested on a few mobile phones around the office and the script works great!
I do thank anyone that is in the process of trying to help me with this and hope I didn't waste anyone's time too much.
03-24-2010, 04:02 PM
P.S. To test your mobile versions of your projects in Firefox you can download and install the User Agent Switcher (https://addons.mozilla.org/en-US/firefox/addon/59)...it's working for me...
03-24-2010, 04:23 PM
I use the same script and was going to answer, as the option explicit will get you every time.
Kudos for figuring it out yourself. You'll never forget the OE thing now!:wink:
03-24-2010, 05:20 PM
lol actually I did forget it once as I encountered the issue before but I'm working on so many things that hey, you can't remember them all !!
The only thing left for this thread now is for an ASP guru to pay us a visit and see if he or she can tighten up the code a bit. There's another example way to detect the user-agent (browser) within that link in the comments but I didn't go for it. If it can be cleaned up that would be good - maybe quicker. Tomorrow I'm going to take another look at it and see what I can do...
03-24-2010, 10:15 PM
There is also going to be the problem of links.
There are several links to several internal pages. Do I want all mobile agents to be redirected only to the index in the mobile directory or be redirected to the mobile page for the original page they requested when they clicked on the link?
I want the user to be taken directly to the mobile version of the page they originally requested. That's inline with proper user experience as well.
This will be a hack. There won't be an .htaccess file to work with so I'm not going there. I'm not too sure about working these redirects on the server isn't an option at this time either.
I believe I'll basically need to do one of two things - correct me if I'm wrong:
a. hack the script to determine the page the user requested and only return the associated page in it's mobile format.
b. simply redirect the user to the index/default of the mobile directory.
Should I use a sub-domain?? I'm kidding, there's no need for a sub-domain in this case...
I shall return with some results...
03-25-2010, 02:13 PM
I've run into the issue where a user searches google, and the redirect is only on our index page. So you get a result for "our locations" and they get the regular site. Some sites like digg give you the option of going to their regular site, but that's why I don't focus too much on the sub-pages getting a redirect to a mobile version.
03-25-2010, 02:16 PM
Ya I think I'm going for the full gamut - get everything working as it should and properly right off the hop so I don't have to go back and edit everything again and again.
It's better for mobile users searching for the sales page to end up on the sales page after a related search for sales within the niche I'm working on right now or for any website search for that matter.
When we think about it, we wouldn't have anything less for our non-mobile users so...
03-25-2010, 03:06 PM
I'm redesigning my entire site, and migrating to the .NET platform this year. With that in mind, I'll work in a better mobile solution and the opportunity for users to choose the regular and mobile version at that time.
03-25-2010, 03:09 PM
So how is it moving to .NET? Difficult? There's probably a sweet mobile solution out there for .NET eh?
03-25-2010, 03:14 PM
I haven't started! :lol:
We're also do a branding exercise in the process, so one is dependent on the other. I'm in a holding pattern while that gets hashed out.
I'm looking forward to the challenge as .NET has many more tools to utilize.
03-25-2010, 03:17 PM
Oh ya for sure...
Righto, let's keep each other updated on these particulars...I'm not sure if our president is interested in ever migrating to .NET but as time goes by he may find to the time to do so...
I'm working on the mobi as we speak...looking nice...I'll post it all in the end...hopefully by the end of this weekend...
03-25-2010, 03:20 PM
OK fine, if you insist: campkins . com / mobi ...
Links aren't working yet and I'm making sure it validates to RDFa as well...