16

window.open()を使用して新しいウィンドウを開き、ユーザーをoauthログインページにリダイレクトします。ただし、ログインに成功した後、ユーザーがアプリにリダイレクトされたときに、window.open呼び出しを使用した前のウィンドウは、iOSで閉じられません。

iPadでは間違ったウィンドウを閉じ、iPhoneではウィンドウをまったく閉じませんでした。このコードは、AndroidおよびデスクトップバージョンのChromeとFirefoxで正常に機能します。

多くの応援の後、私は修正を見つけました(以下に投稿されています)。誰かがより良いアイデアや根本的な原因を持っている場合は、ここに投稿してください。

4

3 に答える 3

8

いくつか検索した後、回避策を投稿するこのツイートを見つけました-https://twitter.com/#!/gryzzly/statuses/ 177061204114685952 by @gryzzly

ここに完全にコピーされました

window.open()ingまたはtarget = "_ blank"の後、window.close()はiOSで機能しませんか?setTimeout(window.close、timeout);を実行します。ここで、タイムアウト>300。

これは、新しいウィンドウを閉じる前に親ウィンドウにフォーカスしているを削除するとともに.focus()、問題を完全に解決しました。

于 2012-05-23T03:07:18.663 に答える
6

これが私が仕事に取り掛かったものです...
window.close関数を機能させることはできませんでした。上記のようにsetTimeoutでも

私はこれを次のようにテストしました:
    windows XP:Chrome20、Firefox12、IE8
    Android gingerbread:androidブラウザ
    Android Ice Cream:androidブラウザ、Firefox
    Ipad:デフォルトのブラウザ(私はサファリだと思います)
    Iphone 3gsと4s:デフォルト


<SCRIPT LANGUAGE=\"JavaScript\">
    function refresh() {
        var sURL = unescape("http://(some web page)/");
        window.location.replace(sURL);
    }
    function closeWindow() {
        var isiPad = navigator.userAgent.match(/iPad/i) != null;
        var isiPhone = navigator.userAgent.match(/iPhone/i) != null;
        if (isiPad || isiPhone) {
           setTimeout( \"refresh()\", 300 );
        } else {
           window.close();
        }
    }
</SCRIPT>

......そしてhtmlコード.....。

<p><input class="bigbutton" type="button" name="cancel" id="cancel" value="Cancel" onClick="closeWindow()"></p>

于 2012-07-26T02:41:06.413 に答える
0

ios 12、13 OK

<p>If the page stops. Please press the button below to continue.</p>
<input id="button" name="button" type="submit" value="Close">

<script>
  var ua = window.navigator.userAgent;

  if (ua.indexOf('iPhone ') > 0) {  
    document.querySelector('#button').addEventListener('click', function (event) {
      event.preventDefault();
      window.close();
    }, false);

    document.querySelector('#button').click();
  } else {
    window.close();
  }
</script>
于 2020-04-16T12:36:16.397 に答える