I recently had the opportunity to work on a project for a large company that was implementing an extensive search repository consolidation. In addition to having the search be accessible through their CRM, they wanted this search to be available on their two intranets as well through an iframe. Suffice it to say these intranets were run on pretty outdated platforms because they had to work on much older versions of Internet Explorer, which was the company standard.
My role in this project was the front-end development of the search interface. With this particular issue, I worked with the company’s back-end developers to implement the iframe into the individual intranets. We ran into a few issues, of course, when testing older versions of Internet Explorer including 9 & 10. What happened was that the meta tag on the parent page (the intranet) that sets the document mode was forcing IE to render the web page as IE8, therefore messing with the styles on the search page in the iframe.
A little research found that “If the top-level page is not in IE9 mode, the iframe element cannot render its contents in IE9 mode, even if the web developer specifies it.” So, since the company wasn’t ready to update their intranet to the latest IE version and therefore force the intranet to render as a newer version of IE, we had to find a work around to force the styles to appear correctly when rendered in an iframe, but not affect the original page.
However that wasn’t the only wrinkle: because this search platform was built using the Salesforce platform, it would be accessed on mobile devices using Salesforce1, which renders its pages using iframes, too. So not only did we need to target the search page styles when they were rendered in an iframe on a desktop, but also AVOID adjusting styles when the search was rendered on the Salesforce1 mobile app.
Well, logic would dictate that at this point, we’d need logic, and not just magical CSS. The logic worked itself out:
IF page renders in an IFRAME in an INTERNET EXPLORER but not a mobile device, THEN change these styles…
So as you can see in the code snippet below, lines 3-9 use the try and catch statements to return the isPageInframe function as true if the page is rendered in an iframe. Then, lines 12-18 show an if else if statement that asks if the page is rendered in an Internet Explorer browser. If it is, then the style changes execute (line 13). Otherwise (else if), if the page is rendered in an iframe and is not being rendered on any mobile platform, then it will execute a different set of style changes (line 17).
This effectively solved the targeting problem as this code lived on the page that was being rendered in an iframe, and no changes needed to be made on the parent page on the intranet. It worked well on Internet Explorer versions 9, 10, and 11, without affecting the original page, pages rendered on mobile devices, or rendered on other browsers on the desktop.
Did you have a similar problem? How did you solve it?