我有一個函數,可以在單擊按鈕時刷新iframe內容。等待iframe內容包含
function changeContent(){
iframe.newContent();
// wait until content contains string "hey"
return true;
}
我想使用while循環,我如何使函數等待字符串,直到返回true? 這是我現在該怎麼訪問的iframe:
var MyIFrame = document.getElementById("myframe");
var MyIFrameDoc = (MyIFrame.contentWindow || MyIFrame.contentDocument);
if (MyIFrameDoc.document) MyIFrameDoc = MyIFrameDoc.document;
感謝
我不需要檢測它加載的第一次,但用戶點擊後按鈕iframe將轉到不同的頁面,我需要檢測該字符串是否出現在第二頁上。會在這種情況發生時加載事件再次觸發?謝謝 – Kristian
隨時加載iframe內容時會觸發onload事件。您可以在更改iframe的src之前添加事件處理程序。在第一次iframe加載頁面後,它不會被激化 –