Captive Wifi Popup: Click a link to open Safari

15,029

Solution 1

EDIT : this solution doesn't work after iOS 10.3. Not sure if that's a feature or a bug : https://forums.developer.apple.com/thread/75498

EDIT2 : Apparently it works again on iOS 11


There is a simple way to do that, if you have control over the captive portal server.

When connecting to a wifi network, iOS devices send a GET request to a bunch of predefined urls (http://www.apple.com/library/test/success.html, ...) , to see if there is Internet connectivity (wispr requests). The iOS device expects the answer <HTML><HEAD><TITLE>Success</TITLE></HEAD><BODY>Success</BODY></HTML>. If the request succeeds, but the answer is different (for example your captive portal page), it triggers the CNA to open.

At this stage, the CNA thinks you are not connected and will show a Cancel button at the top. Every link will open inside the CNA and not in a Safari window, no matter what you do. The CNA is done so that you can get your user through the log-in process. In order to see if the log-in process is done and connection is finally established, the iOS device will now and then send another wispr request. This happens every 40 seconds, or whenever an HTTP request is emitted (navigation within the CNA).

When your server finally answers Success to a wispr request, the CNA will mark as connected, the button at the top will change into Done. At this stage, any link to an external url will close the CNA and open in Safari :)

So to summarize, you can achieve what you want with the following connection steps :

  1. server answers initial wispr request with your CNA page.
  2. the page opens in CNA. In that page, have some JavaScript that immediately triggers navigation within the CNA, for example : <script>window.location.reload(true)</script> this will trigger the iOS device to immediately send another wispr request
  3. server answers this second wispr request with <HTML><HEAD><TITLE>Success</TITLE></HEAD><BODY>Success</BODY></HTML>, this will trigger the CNA to mark as connected
  4. have your CNA page to show a link to an external url

Solution 2

Extracted from an answer by Ryan at How can I open an external link in Safari not the app's UIWebView?

To have a specific link switch to Safari, simply add target="_system" to the link, as in

<a href="http://www.domain.com/" target="_system">Link Text</a>

Or to catch all links in your javascript that have target="_blank", include jQuery and pass them to window.open with the '_system' param. This will work on both iOS and Android.

$(document).on('click', 'a[target="_blank"]', function(ev) {
  var url;

  ev.preventDefault();
  url = $(this).attr('href');
  window.open(url, '_system');
});

Solution 3

Javascript does NOT work fully in CNA, it is disabled for security reason. target="_system" is a safari feature, not a CNA one. ==> briefly, _system fails in CNA.

Share:
15,029

Related videos on Youtube

user3570787
Author by

user3570787

Updated on June 04, 2022

Comments

  • user3570787
    user3570787 about 2 years

    We are having an issue on our network with iOS devices (ipads, iphones etc): After connecting to the SSID, the iphone / ipad immediately opens the Captive Network Assistant (CNA) - it is like a scaled-down browser without navigation buttons etc - that displays our welcome page (ready for the user to authenticate his MAC in the network to give him internet). This CNA is a functin of iOS, and happens automatically.

    I was looking around on this forum how to make the user open his Safari browser by clicking a link (while in the CNA), thus sending him away from the CNA and into Safari (which is where I would prefer him to be).

    I searched phrases such as: "How to set a link to open in safari", but I get results about people using phonegap to do such a thing...
    One user talked about using window.open(myURL, '_system') but I don't know if that is solving my issue.

    Basically my plan is to: - Have my Welcome Page (the page displayed after the user connected to my SSID) detect what type of browser the user's device has. My Welcome Page is hosted at a site which is in the Walled Garden of my controller, so every device can see that Welcome page (whether they have full internet access or not). - If the user has an iOS device, the CNA browser opens automatically. My controller detects the device has a CNA browser and loads a simple page with the message (like): "click here to start to navigate" - During the next few seconds (while the user is digesting the message), my controller gives the user's MAC full internet access - When the user clicks that link in the CNA browser, the CNA closes and then opens Safari, and also forces Safari to open the destination Welcome Page (where I want my user to be, depending on the antenna to which he connected).

    I really hope that all makes sense...

    I found this link about the CNA browser in this forum: Bypasses Apple Captive Network Assistant Login in iOS 7

    But it talks having the user open Safari right from the start (disabling the CNA function), "hoping" that the user opens Safari (rather then going directly to one of his apps). I prefer that the user has to "click to continue", which makes Safari open and he sees my Welcome Page.

    • Admin
      Admin over 9 years
      Correct me if I'm wrong, but I don't think this is possible at all. Usually the only app allowed to open due to a browser action is either Mail or the Default Browser. Otherwise, people could just randomly force others to open applications simply because they visited a webpage.
    • 3pic
      3pic almost 9 years
      @user3570787 I wonder if I have ever seen it. I aim the same thing, but well... Have I already see it working. I think no.
  • Tom
    Tom about 9 years
    I have a similar issue and I've tried using links with target="_system", but they open in the CNA, not in Safari. Anyone got this working? I've seen it working at a hotspot, so it is possible.
  • 3pic
    3pic almost 9 years
    This is a wrong answer, sorry. That does not work.
  • Clown Man
    Clown Man almost 9 years
    Why is this a top most one when it's invalid?
  • bk138
    bk138 over 8 years
    Neither _system nor _blank trigger Safari in iOS 9 CNA. Simply stays in CNA.
  • M to the K
    M to the K over 8 years
    Did anyone find a solution for this ?
  • OCTAGRAM
    OCTAGRAM over 7 years
    Managed to achieve automatic Safari opening by inserting 1-second delay in the CNA page. Then it clicks A element using click(), and it opens in Safari. URL is absolute, target is unset (doesn't work with _blank). Without delay wispr might receive expected response, but links navigate to CNA in an endless loop. And what's notable, if I insert a delay, then second wispr request comes before link navigation could be predicted, so navigation to the link is not the real trigger.
  • sebpiq
    sebpiq over 7 years
    have a look for yourself : github.com/sebpiq/FreedomPortal/blob/master/freedomportal/… I've implemented this exact process and it works like a charm
  • OCTAGRAM
    OCTAGRAM over 7 years
    With 1-second delay things became also fine here: bitbucket.org/snippets/OCTAGRAM/dBq6z
  • sebpiq
    sebpiq over 7 years
    @OCTAGRAM : looked at your code, and I am not conviced that what triggers the CNA to mark as "connected" is the SUCCESS page answered when Safari user-agent is detected. I think it is rather the subsequent wispr requests which you answer with "SUCCESS", and that would explain why you need a 1 sec timeout. In other words, you might have some cases when the timeout is not long enough and the user clicks the link before the CNA is marked "connected", which wouldn't have the intended effect of opening a safari window.
  • sebpiq
    sebpiq over 7 years
    @OCTAGRAM this would be easy to test though : never answer wispr request with "SUCCESS" page and see if your Safari "SUCCESS" page is enough to mark the CNA as connected on its own ...
  • lukyer
    lukyer about 7 years
    not working in iOS 10.3. Captive is not being closed after clicking a link after authentication anymore.
  • sebpiq
    sebpiq about 7 years
    Yes apparently iOS 10.3 broke / removed that feature : forums.developer.apple.com/thread/75498
  • Rui F Ribeiro
    Rui F Ribeiro almost 7 years
    iOS 10 is buggy dealing with CNA. I had to upgrade to 11 beta.
  • sebpiq
    sebpiq almost 7 years
    @RuiFRibeiro so is this solution working again on iOS11?
  • Rui F Ribeiro
    Rui F Ribeiro almost 7 years
    @sebpiq I just tested it now with an iphone 6 with the latest 11 beta in a freebd captive portal I am writing, and it worked. btw, +1
  • ddor254
    ddor254 over 6 years
    @sebpiq where did you find the information about when the wispr request is triggered ??? after 40 seconds and in each HTTP request...
  • vr_driver
    vr_driver about 6 years
    It looks like it may be solved in later version of iOS. forums.developer.apple.com/thread/75498