View Full Version : Injecting HTML into iframe breaks history

4 Oct 2011, 6:49 AM
*** Fixed: See changes made to code below ***


I have routing in place in my application using Ext.History. I also have an iframe in which I sometimes inject HTML. The iframe content doesn't contain any links and users cannot navigate into the iframe. For some reason, IE registers HTML injections as history entries, causing the back button to intermitently navigate back in the iframe instead of the main page (without any effect on the url). In Firefox, it's even worst, the back button doesn't work at all. I have noticed that it will allow me to go back only if history entries are added manually by modifying the hash in the url instead of using Ext.History.add. If I change the iframe element to a div, everything works fine, but the content needs to be isolated from the rest of the page, so I really need an iframe.

Any ideas?

function injectHTMLInIFrame(iFrame, html) {
var iFrame = (typeof iFrame === 'object')? iFrame : document.getElementById(iFrame),
doc = iFrame.contentWindow.document;
doc.body.innerHTML = html;

*Red: Deletions
*Green: Additions