tag:blogger.com,1999:blog-3930375442497799514.post-59164980216460547452008-05-06T09:09:00.000-07:002008-05-06T09:18:14.296-07:002008-05-06T09:18:14.296-07:00Safari iFrame Gymnastics<p>I've got left side navigation that loads documents, either htm or PDF into an iFrame to the right. Every browser worked fine except Safari. I could load a web page into the iFrame, then another, but as soon as I loaded a PDF, it would never update when I set the 'src' attribute to a new URL. I popped an alert box to see what the src value was, and it _was_ setting it, but never rendered the new URL after I had put a PDF in there.</p> <p>I opened the Javascript console, and saw a message having to do with cross-domain security, but I'm working in one domain, so I put that aside. I thought, well, I could tear down the iFrame, construct a new one on the fly and replace it in the DOM...it could work. I tried it and it worked, so I tried to simplify from there.</p> <p>It turned out all I had to do was set the src to the new URL, then remove the iFrame from the DOM and just add it right back. That was enough to get Safari to render the darn thing.</p> <p>Here's what I did...</p> <blockquote><pre><span style="font-size:100%;">var iFrame = document.getElementById('myFrame');
var parent = iFrame.parentNode;
parent.removeChild(iFrame);
parent.appendChild(iFrame);</span></pre></blockquote> <p>Yeah...I know...this should really have no effect, but it works. The parent is just a div that only contains the iFrame, so I didn't have to worry about which child it was. It was the only child.</p>Tom Puleohttp://www.blogger.com/profile/10697521511530638404noreply@blogger.com3