我有一個<div>
被動態創建,它包含一個。 可能會自行關閉,此時將刪除<div>
。iframe上的持久變量?
到目前爲止,我有:
var div = document.createElement('div'), ifr = document.createElement('iframe');
// some styles and stuff here, including ifr.src
ifr.contentWindow.container = div; // Note that domains are the same
// within the iframe's code, possibly a "close" link or after completing an operation
container.parentNode.removeChild(container);
它的工作原理。但是,只有在iframe中的頁面是在那裏開始的頁面。如果鏈接被點擊到另一個頁面,則不再定義window.container
。
我知道我可以使用window.name
來存儲持久化到窗口的數據,但它只限於可以序列化的數據。據我所知,除了分配一個ID並存儲它之外,你不能序列化一個DOM節點。我想避免這種隨意的ID,所以如果任何人都可以提出更好的解決方案,我將非常感激。
啊,是的。我已經在我的代碼的其他地方做過類似的事情,不知道爲什麼我不認爲在這裏應用:D會給它一個測試,並讓你知道。 –
我沒有解釋代碼,因爲我認爲你已經在JS編程中相當先進。如果部分代碼不清楚,請隨時要求澄清。 –
工程。謝謝你提醒我。 –