4

I am running a webapp that is displayed just after a user successfully logged on a wifi network using a captive portal.

On iOS, after the user logs in, my webapp is displayed in the CNA (Captive Network Assistant) popup and the top right button label is turned to "Ok" to allow the user to close this popup.

I want to have a specific behavior in my webapp when it is displayed inside this CNA popup, so I am trying to detect (with Javascript) if my webapp is displayed in such a popup.

I first bet on the window.innerHeight value but on my iPhone 5 it seems difficult :

  • 460px height inside Safari
  • 440px height inside Safari during shared connection or telephone call
  • 459px height inside Captive Network Assistant
  • 439px height inside Captive Network Assistant during shared connection or telephone call

1px difference is, in my point of view, not enough to figure out if I am in this CNA popup.

Is there any other javascript information I can rely on to determine if I am in such a popup ?

Thank you

4

1 に答える 1

8

最後に、ユーザー エージェントで CNA を検出します。CNA 内では、ユーザー エージェントは UA 文字列に「Safari/」を含めません。また、Opera mini、Dolphin、Mercury、Puffin、Atomic、360 Lite などの多数の代替ブラウザでテスト済み...

たとえば、Safari UA 文字列は次のとおりです。

Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25

同じデバイスの CNA 内では、ユーザー エージェント文字列は次のようになります。

Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d

したがって、PHPでは私の検出は次のようになります:

$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);

if ((strpos($userAgent, 'iphone') || strpos($userAgent, 'ipad')) &&
    (strpos($userAgent, 'mozilla/') !== false) &&
    (strpos($userAgent, 'applewebkit/') !== false) &&
    (strpos($userAgent, 'mobile/') !== false) &&
    (strpos($userAgent, 'safari') === false))
{
    // Yes, we are in a CNA popup
    [...]
}
于 2013-11-17T19:40:33.340 に答える