0

I have been scouring the internet trying to figure out how to do this but I am not the best coder. It feel like this should be a very simple task.

I have 2 CSS stylesheets. style1.css and style2.css

I want page1 to load style1.css when not in an iframe and load style2.css when it is in an iframe.

I am loading page1 within an iframe on page2 on my website so all pages and styleshees are on the same domain.

I am trying to load posts from my wordpress site, within an iframe on the same wordpress site but strip away the header menus and footer so they aren't displayed twice.

How can I do this? I have seen people list snippets of jquery code and other things but no instructions on where to put it. The answer I have seen assume you have a good working knowledge of javascript which I don't. Any help would be really appreciated. Thanks.

This question may be a duplicate question but I am looking for a clear answer. A single line of code with no context to someone who doesn't know javascript well is not a clear answer.

  • You can use javascript to [detect if the page is loaded in an iframe](http://stackoverflow.com/questions/925039/detect-iframe-embedding-in-javascript) and then [load the appropriate CSS file](http://stackoverflow.com/questions/574944/how-to-load-up-css-files-using-javascript). – M31 Mar 16 '17 at 17:48
  • 1. From duplicate: `if (window!=window.top) { /* I'm in a frame! */ }` 2. http://stackoverflow.com/questions/574944/how-to-load-up-css-files-using-javascript ---> `var cssId="mainCSS", cssFile = window!=window.top?"iframe.css":"normal.css"; if (!document.getElementById(cssId)) { var head = document.getElementsByTagName('head')[0]; var link = document.createElement('link'); link.id = cssId; link.rel = 'stylesheet'; link.type = 'text/css'; link.href = cssFile; link.media = 'all'; head.appendChild(link); }` – mplungjan Mar 16 '17 at 18:04
  • Put the above in script tags where you would normally have `` – mplungjan Mar 16 '17 at 18:05
  • so like this? ? – Kyle Vaughan Mar 16 '17 at 18:25
  • Ok perfect it works, thank you! – Kyle Vaughan Mar 16 '17 at 18:29

0 Answers0