attach stylesheet to iframe in Firefox (relative URI)

J

juergen.riemer

Hi all,

I have a problem in attaching an external stylesheet to a newly created
iframe in Firefox (1.5.0.2).
If I use the code below (with a relative address to the file) the
stylesheet would not be applied.
I have to indicate the absolute path:
var uriStylesheet = "http://localhost:8080/panel/styles.css";
to make it work in Firefox.
NB: if I try to attach the external stylesheet to the topmost body (the
main document) I could use the relative path without a problem.

any ideas?

greetz

mord

<html>
<body>
<script>

oPanel = document.createElement("IFRAME");
oPanel.src = "about:blank";
document.body.appendChild(oPanel);
oPanel.addEventListener("load", function(){
var oImage = oPanel.contentDocument.createElement("IMG");
oPanel.contentDocument.body.appendChild(oImage);
attachStylesheet();
}, false);

function attachStylesheet(){

var uriStylesheet = "/jPanel/styles.css";
var uriStylesheet = "http://localhost:8080/panel/styles.css";
var oStylesheet = oPanel.contentDocument.createElement("LINK");
oStylesheet.rel = "stylesheet";
oStylesheet.type = "text/css";
oStylesheet.href = uriStylesheet;
var oHead = oPanel.contentDocument.getElementsByTagName('head')[0];
if(oHead){
oHead.appendChild(oStylesheet);
}
}

</script>
</html>
</body>
 
M

Martin Honnen

I have a problem in attaching an external stylesheet to a newly created
iframe in Firefox (1.5.0.2).
oPanel = document.createElement("IFRAME");
oPanel.src = "about:blank";

Well what do you expect the browser to do with a relative URL if you
simply load about:blank in the window/frame? To resolve a relative URL a
base URL is needed but a document loaded from about:blank does not
really have one. Load a normal http: or file: URL in the frame and then
the browser is able to resolve a relative URL.
 
J

juergen.riemer

Martin,

I thought the path of the onwner document was taken into consideration
in this case (IE seems to do this), well I was quite "IE-way-thinking"
and wrong. Thanks for clarification

lg

mord
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top