편집 : 테스트에서 iframe이 비동기 적으로로드됩니다 (완전히 확신 할 수는 없지만). 나는 작동하는 700 밀리 초의 기간 후에 함수를 호출하여 그것을 수정했다 &. 그래서 그것은 그들이 비 동시성이라고 생각하게 만듭니다. 나는이 작업을 수행 :IFrames가 비동기식으로로드됩니까? 그렇지 않은 경우 왜이 오류가 발생합니까?
insertHTMLIntoIFrame(HTML); //$("#updaterIframe").contentWindow.location.reload(true);
setTimeout("convertToUpdatable()", 700);
최종 편집
나는 내 웹 페이지 내 iframe이 뭔가 이상한 발생하는있다. 내 함수는 "업데이트 가능"클래스 인 모든 HTML 요소에 대해 iframe을 검색합니다. &은 해당 요소를 텍스트 영역으로 변환합니다.
내 문제 : 나는 (그들이 iframe에있을 때) 다음 함수를 업데이트 할 수있는 요소 중 하나를 찾을 수없는 iframe이에 일부 HTML을 삽입 한 후 바로 기능
를 호출하는 경우 하지만
alert();을 표시하여 함수 실행을 지연하면; 업데이트 할 수있는 요소에 대한 iframe을 검색하기 전에 iframe의 모든 요소를 &으로 변환합니다.
이렇게하면 iframe이 비동기식으로로드된다고 생각합니까? 맞습니까? 만약에 무엇이 잘못되어 가고 있지 않습니까? iframe을 새로 고치거나 전체 iframe이로드 될 때까지 함수를 호출하지 못하도록하는 방법이 있습니까?
// I call the functions in the following order:
insertHTMLIntoIFrame("blah");
convertToUpdatable();
function convertToUpdatable()
{
// Post: Convert all HTML elements (with the class 'updatable') to textarea HTML elements
// and store their HTML element type in the class attribute
// EG: Before: <p class="updatable Paragraph1"/> Hello this is some text 1 </p>
// After : <p class='updatableElementTitle'>Paragraph1</p><textarea class="updatable Paragraph1 p"/> Hello this is some text 1 </textarea>
if (STATE != 1) { return; }
// if I dont have this line then I cant find any updatable elements in the iframe
alert("Displaying website with updatable regions");
$("#updaterIframe").contents().find(".updatable").each(function()
{
var className = this.className;
var nodeName = this.nodeName;
var title = getTitleName(this);
$(this).replaceWith("<p class='updatableElementTitle'>"+title+"</p><textarea class='"+ className + " " + nodeName +"'>"+$(this).html() +"</textarea>");
});
STATE = 0;
}
function insertHTMLIntoIFrame(htmlSrc)
{
try
{
var ifrm = document.getElementById("updaterIframe");
ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
ifrm.document.open();
ifrm.document.write(htmlSrc);
ifrm.document.close();
}
catch (ex) { alert("In insertHTMLIntoIFrame(): "+ex); }
}