私は実際の問題を「解決」し、「なぜこれが問題だったのですか?」という質問を変更しました。 ; google.com wouldn」iframeからhtmlをiframeの親に読み込むときにブラウザがハングするのはなぜですか?
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>iFrame Page Loading</title>
<script type='application/javascript' src='http://code.jquery.com/jquery-latest.js'></script>
<script type='application/javascript'>
$(document).ready(function() {
var $form = $('form');
var $target = $('#target');
// Create an invisible iframe right after the form.
var $iframe = $('<iframe name="_hidden"></iframe>').hide();
// Change this line to the commented version after it to fix all problems:
$target.append($iframe);
// $target.parent().append($iframe);
// Make the form target the iframe.
$form.attr('target', '_hidden');
// Make the form action the 'ajax_load' value.
$form.attr('action', $form.find('.ajax_load').attr('value'));
// On form submit, create an event to replace $target with iframe's
// contents on iframe load.
$form.submit(function() {
$iframe.bind('load', function() {
$target.html($iframe.contents().find('*').html());
// Uncommenting this line fixes Firefox but not Safari - see below
// $target.append($iframe);
$iframe.unbind('load');
});
});
});
</script>
</head>
<body>
<form method='get' action=''>
<input type='hidden' class='ajax_load' value='test.html' />
<input type='submit' value='Load' />
</form>
<div id='target'></div>
</body>
</html>
は(他のであれば、ローカルファイルだと何かに「test.htmlという」を変更することでこれをテストすることが可能です:私はここにこのコードを持っている
これはまさに私が望むことです:まず、#targetの中に目に見えないiframeを作成し、フォームを変更して新しいURLを取得し、iframeをターゲットにするようにフォームを変更します。送信時に、iframeがグラブされたコンテンツを読み込みます。読み込み時には、iframeのhtmlが#targetのhtmlに置き換わります。
ブラウザがiframeを読み込んだ後、読み込み中に何か問題が発生することが問題です。 Firefoxは何がうれしく、チャーミングを続けているかは言いません。 Safariは何かが間違って停止してしまったと言います。私がそこから得ることができる最良の情報は、iframe読み込みで何らかの野性的な再帰が起こっているということです。これは理想的ではありません。
ターゲットの外に隠れたiframeを置くと問題が解消します。また、htmlを読み込んだ後、iFrameがターゲットに再度追加されていることを確認した場合にのみ、Firefoxで消えてしまいます。
実際の問題はもうありませんが、私がやっていたことをするのがどうして問題なのかをよく知りたいと思います。隠されたiframeからHTMLを読み込み、そのiframeの親ノードの
ブラウザ+バージョン+運用システムを指定してください。 – jackJoe