0

The plan:

I have an iframe, called frame.html. If the frame.html is shown alone (not inside a page) it should load the no_frame.css.

If the frame.html is shown as an iframe inside a page it should load the frame.css.

The CSS should change divs inside the frame.html, so its important that the script check out if the page stays alone or inside an iframe. And I want to use this script in general for iframes, not only for the iframe.html.

Is there a better way to achieve this?

UPDATE:

@Alex K. - like this??:

<script type="text/javascript">
  jQuery(document).ready(function($){
  if (window!=window.top) { framed=true }

    var cssId = 'myCss';  // you could encode the css path itself to generate id..
    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 = 'http://website.com/css/frame.css';
        link.media = 'all';
        head.appendChild(link);
    }
});

Sven
  • 41
  • 4
  • `if (window!=window.top) { framed=true }` then [How to load up CSS files using Javascript?](http://stackoverflow.com/questions/574944/how-to-load-up-css-files-using-javascript) – Alex K. Apr 24 '15 at 13:38
  • And if the difference between frame.css and no_frame.css is minimal, you can alternatively add a flag and scope the relevant css – Francis Nepomuceno Apr 24 '15 at 13:48
  • @Neps: how will this look like? Primary I only want to "display:none" some divs. – Sven Apr 24 '15 at 13:50
  • Pretty sure I suggested the same thing @Neps just said on the same question earlier today already … so why did you delete it (assuming that was yours, which I think was the case)? – CBroe Apr 24 '15 at 13:52
  • Follow @AlexK.'s comment, then also add a class i.e.``. From there, you only need to maintain 1 stylesheet. – Francis Nepomuceno Apr 24 '15 at 13:52
  • Sry, my js skills are very low - so is my script on top wrong? – Sven Apr 24 '15 at 13:58

0 Answers0