2011-08-09 3 views
1

그래서 실제 문제를 "해결"하고 "왜 이것이 문제였습니까?"라는 질문을 변경했습니다. ; google.com 같으면 '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을로드하면로드하는 데 문제가 있다는 것이 문제입니다. 파이어 폭스는 무엇을하고 행복하게 chugging을 말하지 않습니다. 사파리는 무언가가 잘못되어 멈추었다고 말합니다. 내가 얻을 수있는 최상의 정보는 iframe 로딩과 관련하여 일종의 야생 재귀가 발생하고 있다는 것입니다. 이상적이지 않습니다.

숨겨진 iframe을 대상 밖으로 놓으면 문제가 사라집니다. 또한 iframe이 html을로드 한 후 대상에 다시 추가되는지 확인하는 경우에만 Firefox에서 사라집니다.

더 이상 실용적인 문제가 없지만 숨겨진 iframe에서 HTML을로드하여 HTML 내용을 대체하는 데 사용하는 이유가 무엇인지 정확히 알고 싶습니다. iframe의 부모 노드에 대한

+0

어떤 브라우저 + 버전 + 운영 체제를 지정하십시오. – jackJoe

답변

0

코드에 메시지를 넣으면 정확히 어떤 줄이 있는지 찾을 수 있습니다. 그것은 그 잘못을 좁혀 야합니다.

+0

나는 그것을 시험해 그것이 어디에서나 발견 할 수있다. 내가 알기로는 이러한 경고를 기반으로 $ iframe의로드 바인드는 한 번만 호출됩니다. 내 코드가 매달리기 시작할 때까지 더 이상 실행되지 않는 것 같습니다. – meustrus

+0

Google +1 버튼 (iFrame)을 추가 한 웹 사이트에서 비슷한 문제가 발생했습니다. 네트워크 속도가 느려져서 여기에있을 수 있습니까? – Jack

+0

파일이 내 로컬 컴퓨터에있을 수 있기 때문에 수 없습니다. – meustrus

관련 문제