Community discussions

MikroTik App
 
wilburt
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 86
Joined: Tue Aug 24, 2010 3:07 am

Redirecting a user login page based on mobile device

Tue Oct 05, 2010 7:00 am

Hi,

I am trying to see if it is possible to use some javascript to detect the user's device and redirect them to the appropriate login page?

For example.
A user connects to the hotspot then the login.html will detect the device (using javascript?) and if it matches to a mobile device it redirects the login page to a separately login page that I have created in a different folder (similar to how different language login screens can be done)

Is this possible? If so I can't seem to trigger my javascript code from the page.

THanks
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: Redirecting a user login page based on mobile device

Tue Oct 05, 2010 7:08 am

http://www.w3schools.com/js/js_browser.asp

You can then redirect with JavaScript by submitting a form, for example.

I tend to use external servers for the login pages that run dynamic scripting languages that make those decisions (MVC with different HTML templates are loaded based on the user agent string presented to the server).
 
wilburt
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 86
Joined: Tue Aug 24, 2010 3:07 am

Re: Redirecting a user login page based on mobile device

Tue Oct 05, 2010 3:21 pm

Thanks for the information.

However, I did try running some basic javascript just on the login form and nothing happened.

The script that I was running was a simple pop dialog box

alert("hello");

and the script never ran.

Is there a restriction on the javascript within the login page?

Thanks
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: Redirecting a user login page based on mobile device

Tue Oct 05, 2010 4:09 pm

There is not. The default login pages use JavaScript. Also, there cannot be a javascript limitation on the server - it just sends HTML to the client, which interprets it. Are you sure your client supports JavaScript? That it is turned on? That there is no browser add on that blocks it? That it implements that particular function? That your syntax is right?

Wild guesses, I am not qualified to troubleshoot HTML and JavaScript.
 
wilburt
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 86
Joined: Tue Aug 24, 2010 3:07 am

Re: Redirecting a user login page based on mobile device

Wed Oct 06, 2010 5:33 am

Thanks everyone for the replies. I have managed to get it to work now. It was a unclosed " that caused the javascript not to run.

Everything is working as expected.

However, I do have one additional question on the mobile login. I have tested connecting to the WiFi via the iPhone and at the moment I select that Wifi network to connect to, it pops open the login page. When I click login I don't get directed to my specified page in the dst variable. It just closes that internal browser and returns to the wifi settings in the phone.

Is there a way to force the redirect on the iPhone and possibly other mobile devices?

Has anyone solved this problem? Or is there just no way around it?

Thanks again.
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: Redirecting a user login page based on mobile device

Wed Oct 06, 2010 6:05 am

I am not entirely sure of this as I don't do web development (phew), but I am under the impression that the iPhone is a WISPr client - look that up on wiki if you do not know it - and as the default HTML pages do send WISPr messages the phone should be able to determine when a login has taken place, so it can cut the process short and not show the final redirect. If that theory is right you might be able to turn that behavior off by removing all the WISPr XML from your login pages. That will also affect clients installed on laptops etc., Boingo and iPads - among others - use WISPr. If you don't have roaming agreements with them I doubt you will miss WISPr much. Of course, if you have already turned that off by not having the XML in your login pages my theory is dead wrong, which it might be, anyway.
 
wilburt
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 86
Joined: Tue Aug 24, 2010 3:07 am

Re: Redirecting a user login page based on mobile device

Thu Oct 07, 2010 4:09 am

Thanks for the reply. It turns out to be a default feature of (specifically) iOS3.x and above, known as CNS. If i turn this off, then everything is fine.
 
romivaly
just joined
Posts: 10
Joined: Mon Jun 06, 2011 11:04 am

Re: Redirecting a user login page based on mobile device

Mon Jun 06, 2011 11:34 am

Hello

I was searching some topics and came to this topic.
I have now 2 customers who want mobile and PDA support so i need to create a login page for mobile and PDA's so users get the right view of the login that suite there browser.

Because i am very new here it seems very difficult to me.

Can you help me with this issue.

1. What do i need for creating a mobile / pda login page
2. i see the link about java script in this topic but how do i customized it so it redirects

So please help me
 
seekingserenity
just joined
Posts: 1
Joined: Sat Mar 10, 2012 12:40 pm

Re: Redirecting a user login page based on mobile device

Sun Mar 11, 2012 7:48 pm

I realize this is a pretty old thread already, but am struggling with serving up a mobile-ready login page that actually logs in. I'm more web designer than hotspot code manipulator...

I have a login.html page which has an auto javascript redirect if a mobile / handheld device is detected - this is working very well and goes to mobilogin.html. This means non-mobile users see the full version of the login.html page for laptop/desktop screen, while mobile users see a login page optimized for their smaller screens - each with an associated css file.

For interest sake, here's the javascript redirect code:
<script language=javascript>
var redirectagent = navigator.userAgent.toLowerCase(); var redirect_devices = ['vnd.wap.xhtml+xml', 'sony', 'symbian', 'nokia', 'samsung', 'mobile', 'windows ce', 'epoc', 'opera mini', 'nitro', 'j2me', 'midp-', 'cldc-', 'netfront', 'mot', 'up.browser', 'up.link', 'audiovox', 'blackberry', 'ericsson', 'panasonic', 'philips', 'sanyo', 'sharp', 'sie-', 'portalmmm', 'blazer', 'avantgo', 'danger', 'palm', 'series60', 'palmsource', 'pocketpc', 'smartphone', 'rover', 'ipaq', 'au-mic', 'alcatel', 'ericy', 'vodafone', 'wap1', 'wap2', 'teleca', 'playstation', 'lge', 'lg-', 'iphone', 'android', 'htc', 'dream', 'webos', 'bolt', 'nintendo']; for (var i in redirect_devices) {if (redirectagent.indexOf(redirect_devices) != -1) {location.replace("mobilogin.html");}}
</script>


Then the trouble starts... As soon as I login on the mobilogin.html page, it of course redirects to the previous url - namely login.html. Which then redirects to mobilogin.html... I end up in a lovely circle of login and redirect!

How do I get mobilogin.html to auto-redirect to a page TWO urls back, the one the client was trying to access before the first login page showed up? Or to simply login and proceed to the wider web? Is there a way to manipulate the "dst" command?

::update::
Have created a mobi folder (similar to creating a different language folder), with a login.html specific to mobile devices. I now can login, and then hit the status page - nothing further. Will update this post if and when I find a work-around, as I'm sure I'm not the only one struggling on.

::update2::
Am about to give up trying to find a way around the link-redirect to get it to go back to session start / url request / browser home page that triggered login.html - and simply set that to the company website home page.

::update3::
Right - so now the mobile login.html will load the status page (and not further) - but only if Cookies are enabled on the hotspot and the user has been there before. If Cookies are not enabled, the login.html generates loop after loop until I end up with a url that looks like 192.168.../mobi/mobi/mobi/mobi/mobi etc... Is there ANYONE out there that can help get this thing to work?
Last edited by seekingserenity on Mon Mar 12, 2012 10:55 pm, edited 1 time in total.
 
ulzii
just joined
Posts: 8
Joined: Wed Feb 15, 2012 12:03 pm
Location: mongolia

Re: Redirecting a user login page based on mobile device

Thu Aug 09, 2012 7:29 am

Hi, I have problem with mobile hotspot page. I created mobile/login.html directory. So users redirected to the mobile login page and working file. But there is one problem. When mobile users load the mobile login page, user's requested web page not loading. Any suggestion. Sorry for my bad english.

Thank you for any suggestion.
 
Ehman
Member
Member
Posts: 389
Joined: Mon Nov 15, 2010 10:49 pm

Re: Redirecting a user login page based on mobile device

Fri Sep 28, 2012 3:52 pm

Hi, I have problem with mobile hotspot page. I created mobile/login.html directory. So users redirected to the mobile login page and working file. But there is one problem. When mobile users load the mobile login page, user's requested web page not loading. Any suggestion. Sorry for my bad english.

Thank you for any suggestion.
Did you fix the problem, I'm sitting with the same problem now! :(
 
User avatar
vipe
Member Candidate
Member Candidate
Posts: 166
Joined: Thu Sep 14, 2006 10:05 pm

Re: Redirecting a user login page based on mobile device

Thu Oct 25, 2012 2:09 pm

same problem
 
Ehman
Member
Member
Posts: 389
Joined: Mon Nov 15, 2010 10:49 pm

Re: Redirecting a user login page based on mobile device

Thu Oct 25, 2012 2:38 pm

same problem
Its a DNS related thing "I Think" ...but I don't know how to fix it yet :(

EDIT: sorry, I misread the thread name and replied with something weird, I did the same by changing something in the html files on the router, I had the same problem
Last edited by Ehman on Mon Oct 29, 2012 10:21 am, edited 1 time in total.
 
ulzii
just joined
Posts: 8
Joined: Wed Feb 15, 2012 12:03 pm
Location: mongolia

Re: Redirecting a user login page based on mobile device

Mon Oct 29, 2012 5:22 am

Solved my problem.

Who is online

Users browsing this forum: almdandi, raiser, TikYAN and 100 guests