8

私が扱っているジレンマは、jquery-bbq コードで、IE6 と IE7 がサポートしていないためhashchange、履歴状態を保持するためにページを 2 回ロードすることです。

コードはサーバー側とクライアント側の両方で 2 回実行されるため、これには悪影響があります。iframe の作成に使用されるメソッドは次のとおりです。

  if ( is_old_ie ) {

    // Create hidden IFRAME at the end of the body.
    iframe = $('<iframe src="javascript:0"/>').hide().appendTo( 'body' )[0].contentWindow;

    // Get history by looking at the hidden IFRAME's location.hash.
    get_history = function() {
      return get_fragment( iframe.document.location.href );
    };

    // Set a new history item by opening and then closing the IFRAME
    // document, *then* setting its location.hash.
    set_history = function( hash, history_hash ) {
      if ( hash !== history_hash ) {
        var doc = iframe.document;
        doc.open().close();
        doc.location.hash = '#' + hash;
      }
    };

    // Set initial history.
    set_history( get_fragment() );
  }

の src を持つ空白の iframejavascript:0が作成されます。document.openメソッドが呼び出され、 で開くページのデフォルトとして親ウィンドウのをlocation.href取得するようです.open

基本的に、同じ URL を 2 回開かないようにコードを変更する必要があるため、デフォルトをオーバーライドして、?iframe=true などのパラメーターを指定しようとしています。

例:

http://example.com/views/step-2?one=two

IE では、上記のページが読み込まれ、iframe に再度読み込まれます。サーバー側のコードは2 回実行されますが、そうなってほしくありません。

パラメータが指定され&iframe=1ている場合にサーバー側のコードが実行されないように、URIに追加したいと考えています。iframe

最も明白なことは次の 2 つです。

  1. iframe の src を設定しますが、これは悪影響を与える可能性があり、理由があると確信しています。
  2. を使用する代わりにdocument.open.close、使用iframe.location.hrefして手動で href に設定します。

誰かが iframe ハッキングの経験がある場合は、いくつかのヒントをいただければ幸いです。

編集:私が考えた別の回避策は、iframeがdocument.open1に等しい「iframeloading」のセッション変数を作成し、iframeにロードイベントハンドラーを設定する前にセッション変数を設定するiframe / ajaxを介してページをロードすることですload を使用して 0 に戻し、セッション変数が 1 に設定されている場合はサーバー側のコードが実行されないように調整します。

$('<iframe src="/iframe-loading.php"/>').hide().appendTo('body');
document.open().close()
 $( document.defaultView ).load(function() {
    $('<iframe src="iframe-doneloading.php/>').hide().appendTo('body');
});
4

1 に答える 1

1

About "Is there a standard way of defining the href that opens in a document.open call?"

No, there is not.

于 2011-09-21T11:28:04.233 に答える