Search

4/02/2009

set iframe content

http://chunghe.googlecode.com/svn/trunk/experiment/iframe.set.content.htm
set iframe content - 必須要用 open/write/close,不可以直接用 innerHTML
<iframe>hello world</iframe>
chrome/ie: fail, ff3: ok
<iframe src="data:text/html;charset=utf8,%3C!DOCTYPE ..."></iframe>
ie: fail, chrome/ff3:ok


if (this.browser.ie || this.browser.webkit || this.browser.opera || (navigator.userAgent.indexOf('Firefox/1.5') != -1)) {
//Firefox 1.5 doesn't like setting designMode on an document created with a data url
try {
//Adobe AIR Code
if (this.browser.air) {
doc = this._getDoc().implementation.createHTMLDocument();
var origDoc = this._getDoc();
origDoc.open();
origDoc.close();
doc.open();
doc.write(html);
doc.close();
var node = origDoc.importNode(doc.getElementsByTagName("html")[0], true);
origDoc.replaceChild(node, origDoc.getElementsByTagName("html")[0]);
origDoc.body._rteLoaded = true;
} else {
doc = this._getDoc();
doc.open();
doc.write(html);
doc.close();
}
} catch (e) {
//Safari will only be here if we are hidden
check = false;
}
} else {
//This keeps Firefox 2 from writing the iframe to history preserving the back buttons functionality
this.get('iframe').get('element').src = 'data:text/html;charset=utf-8,' + encodeURIComponent(html);
}

沒有留言: