script> function cleanContent() { var $iFrameContents = $('iframe').contents(), $entryContent = $iFrameContents.find('div.file-view'); $iFrameContents.find('html').replaceWith($entryContent); // Next restore the style-sheets var stylesheet = $('iframe').contents().find('link[rel="stylesheet"]').prependTo($iFrameContents.find('div.file-view')); } $('iframe').load( function(){ console.log("Cleaning content"); cleanContent(); });