簡體   English   中英

javascript:在寫入iframe頁面之前,先等待它加載(但不是從觸發加載的頁面開始)

[英]javascript: waiting for an iframe page to load before writing to it (but not from the page that's triggered the load)

抱歉,如果在其他地方也回答過此問題,但我無法找到它的引用。 (我承認,可能是因為沒人願意做這種愚蠢的事情)。

因此,我有一個包含三個iframe的頁面。 一個事件觸發javascript函數,將新頁面加載到其他兩個iframe中; ['topright']和['bottomright']。

但是,正在加載到iframe“頂部”的頁面中的javascript然后需要將信息發送到“底部” iframe中的元素。

window.frames ['bottomright']。document.subform.ID_client = client; 等等

但這僅在頁面已完全加載到右下框架中時有效。 那么,在“右上” iframe中的代碼在寫入之前,檢查並確保右下框中的form元素實際上可用於寫入的最有效方法是什么? 請記住,頁面加載尚未從右上框架觸發,因此我不能簡單地使用onLoad函數。

(我知道這聽起來像是一條曲折的曲折路線,用於將數據從一頁轉移到另一頁,但這是另一回事了。客戶端總是正確的,等等... :-)

如果我沒有理解你的問題,你控制所有的幀的內容,所有的幀內容是來自同一個域,你可以觸發一個onload的事件bottomright框架來自於該數據topright ,而不是試圖推動它。

bottomright甚至可以調用一個函數topright ,並要求它數據(這在我的腦海里仍然是的一種形式)。

像這樣:

// topright
function pushData(frame, form, name, value) {
    frame.document.forms[form].elements[name] = value;
}

// bottomright
window.onload = function () {
    top.frames['topright'].pushData(window, 'sub_form', 'ID_client', 'client');
}

未經測試。 我不是100%確定從bottomright通過window是可以的,在這種情況下,這可能是替代方案:

// topright
function pushData(frame, form, name, value) {
    top.frames[frame].document.forms[form].elements[name] = value;
}

// bottomright
window.onload = function () {
    top.frames['topright'].pushData('bottomright', 'sub_form', 'ID_client', 'client');
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM