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);
}
});