<!doctype html>

<html lang="ko">

<head>

  <meta charset="utf-8" />

  <meta name="viewport" content="width=device-width,initial-scale=1" />

  <title>위대한육아 열기…</title>


  <script>

  (function () {

    // ⛳️ Set these:

    var IOS_APP_ID = '6737761882’

    var ANDROID_PACKAGE = 'com.widaehannyuga';

    // Build deep path from the current URL:

    //  https://widaehanyuga.web.app/contentDetail/50

    //   → scheme: widaehannyuga://contentDetail/50

    var path = (location.pathname.replace(/^\/+/, '') || '');

    var qs   = location.search || '';

    var hash = location.hash || '';

    var schemeUrl = 'widaehannyuga://' + path + qs + hash;


    // Store links (prefer app-deep links, then web as fallback)

    var iosStoreApp = 'itms-apps://itunes.apple.com/app/id' + IOS_APP_ID;

    var iosStoreWeb = 'https://apps.apple.com/app/id' + IOS_APP_ID;

    var playApp     = 'market://details?id=' + ANDROID_PACKAGE';

    var playWeb     = 'https://play.google.com/store/apps/details?id=' + ANDROID_PACKAGE;


    // Platform detection

    var ua = navigator.userAgent || '';

    var isAndroid = /Android/i.test(ua);

    // iPadOS reports as Mac sometimes; include touch-capable Macs

    var isIOS = /iP(hone|od|ad)/.test(ua) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);


    // Smart App Banner for Safari (adds “Open/Install” banner)

    // Include the deep link as app-argument so "Open" goes to the right place

    var meta = document.createElement('meta');

    meta.setAttribute('name', 'apple-itunes-app');

    meta.setAttribute('content', 'app-id=' + IOS_APP_ID + ', app-argument=' + schemeUrl);

    document.head.appendChild(meta);


    var didHide = false;

    var fallbackTimer = null;


    document.addEventListener('visibilitychange', function () {

      // If page becomes hidden soon after we attempt the scheme, the app likely opened

      if (document.hidden) didHide = true;

    });


    function fallbackToStore() {

      if (didHide) return; // app likely opened; don’t yank user to store

      if (isIOS) {

        // App Store app, then web as backup

        location.href = iosStoreApp;

        setTimeout(function(){ location.href = iosStoreWeb; }, 1500);

      } else if (isAndroid) {

        // Play Store app, then web as backup

        location.href = playApp;

        setTimeout(function(){ location.href = playWeb; }, 1500);

      } else {

        // Desktop or unknown → send to iOS web listing (or your marketing page)

        location.href = iosStoreWeb;

      }

    }


    function attemptOpenApp() {

      // Attempt to open the installed app via custom scheme

      location.href = schemeUrl;

      // If it doesn’t open within ~1.2s, assume not installed → store

      fallbackTimer = setTimeout(fallbackToStore, 1200);

    }


    // Auto-attempt on load (some in-app browsers block this; the buttons below cover that)

    window.addEventListener('load', attemptOpenApp);


    // Expose button handlers

    window.openAppManually = function () {

      if (fallbackTimer) clearTimeout(fallbackTimer);

      attemptOpenApp();

    };

    window.installApp = function () {

      if (fallbackTimer) clearTimeout(fallbackTimer);

      fallbackToStore();

    };

  })();

  </script>


  <style>

    body { font-family: -apple-system, system-ui, "Pretendard", "Noto Sans KR", sans-serif; margin: 0; padding: 24px; }

    .wrap { max-width: 520px; margin: 0 auto; text-align: center; }

    h1 { font-size: 20px; margin: 0 0 12px; }

    p { color: #555; margin: 0 0 20px; }

    button { display: inline-block; padding: 12px 16px; border-radius: 12px; border: 0; margin: 6px; font-size: 16px; }

    .primary { background: #111; color: #fff; }

    .ghost { background: #f3f3f3; color: #111; }

  </style>

</head>

<body>

  <div class="wrap">

    <h1>앱을 여는 중…</h1>

    <p>열리지 않으면 아래 버튼을 눌러 주세요.</p>

    <button class="primary" onclick="openAppManually()">앱에서 열기</button>

    <button class="ghost" onclick="installApp()">앱 설치</button>

  </div>

</body>

</html>