473,588 Members | 2,452 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IFRAME initalization and stylesheet in DOM-created IFRAME

Hi everyone

I have a JavaScript app that creates an IFRAME through DOM
(createElement( 'IFRAME')) However, that IFRAME does not have any content
yet.

alert(iframe.co ntentWindow.doc ument.documentE lement)

gives null.

How can I, through DOM, create the root element? I can't find it.

My following question: In that IFRAME I need to load a stylesheet.
However, I can't seem to get the LINK in IFRAME thing working. I tried,
but IE 6 just seems to ignore the stylesheet speicified in the LINK. I
have the following code, in which win is the window of the IFRAME
(iframe.content Window).

eLink = win.document.cr eateElement("LI NK");
eLink.setAttrib ute("REL","styl esheet");
eLink.setAttrib ute("HREF", GUIstyleSheet);
eLink.setAttrib ute("TYPE","tex t/css");
win.document.do cumentElement.a ppendChild(eLin k);

But this:

win.document.op en();
win.document.wr iteln("<HTML><H EAD>");
win.document.wr iteln("<LINK REL=\"styleshee t\"
HREF=\""+GUIsty leSheet+"\" TYPE=\"text/css\">");
win.document.wr iteln("</HEAD><BODY></BODY></HTML>");
win.document.cl ose();

does work? Does anyone know why? Or what I am doing wrong?

Thanks!
Vincent

Jul 23 '05 #1
7 2696
DU
Vincent van Beveren wrote:
Hi everyone

I have a JavaScript app that creates an IFRAME through DOM
(createElement( 'IFRAME')) However, that IFRAME does not have any content
yet.

and it won't until you assign the src value.

http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-43933957
alert(iframe.co ntentWindow.doc ument.documentE lement)

contentWindow refers to a window object, just as iframe. contentWindow
is not a DOM 2 attribute anyway.
gives null.

How can I, through DOM, create the root element? I can't find it.

My following question: In that IFRAME I need to load a stylesheet.
However, I can't seem to get the LINK in IFRAME thing working. I tried,
but IE 6 just seems to ignore the stylesheet speicified in the LINK. I
have the following code, in which win is the window of the IFRAME
(iframe.content Window).

eLink = win.document.cr eateElement("LI NK");
eLink.setAttrib ute("REL","styl esheet");
eLink.rel = "stylesheet ";
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-41369587

Whenever you can, you should avoid setAttribute as a way to assign an
attribute; setAttribute does not work well in all browsers.

eLink.setAttrib ute("HREF", GUIstyleSheet);
I assume that GUIstyleSheet is a DOMstring variable.

eLink.href = GUIstyleSheet;
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-33532588
eLink.setAttrib ute("TYPE","tex t/css");
eLink.type = "text\/css";
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-32498296
win.document.do cumentElement.a ppendChild(eLin k);

win.document.he ad.appendChild( eLink);

DU
But this:

win.document.op en();
win.document.wr iteln("<HTML><H EAD>");
win.document.wr iteln("<LINK REL=\"styleshee t\"
HREF=\""+GUIsty leSheet+"\" TYPE=\"text/css\">");
win.document.wr iteln("</HEAD><BODY></BODY></HTML>");
win.document.cl ose();

does work? Does anyone know why? Or what I am doing wrong?

Thanks!
Vincent

Jul 23 '05 #2
>
Hi everyone

I have a JavaScript app that creates an IFRAME through DOM
(createElement( 'IFRAME')) However, that IFRAME does not have any content
yet.


and it won't until you assign the src value.


But thats weird. It must be possible to create an empty document and
fill it dynamically, right? Else I'll have to do

iframe.src='abo ut:blank';

and thats ugly (I think).

Vincent

ps Thanks for the CSS info, that helped

Jul 23 '05 #3
Vincent van Beveren wrote:
Hi everyone

I have a JavaScript app that creates an IFRAME through DOM
(createElement( 'IFRAME')) However, that IFRAME does not have any content
yet.


and it won't until you assign the src value.


But thats weird. It must be possible to create an empty document and
fill it dynamically, right? Else I'll have to do

iframe.src='abo ut:blank';


iframe.src = 'blank.html';

where blank.html is a valid blank page.

Then, you modify the DOM of blank.html

If you run it from a web server, and try to modify the DOM of
about:blank, you will run into security issues.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/
Jul 23 '05 #4
>>>> I have a JavaScript app that creates an IFRAME through DOM
(createElement( 'IFRAME')) However, that IFRAME does not have any
content
yet.
and it won't until you assign the src value.


But thats weird. It must be possible to create an empty document and
fill it dynamically, right? Else I'll have to do

iframe.src='abo ut:blank';

iframe.src = 'blank.html';


But thats still not very neat. I mean, its not logical to first have to
load an external html file inorder to dynamically create one? Shouldn't
something like

iframe.contentD ocument = new Document(those nice W3C things);

or

iframe.createCo ntentDocument(t hose nice W3C things);

work/be implemented?

Vincent

Jul 23 '05 #5
Vincent van Beveren wrote:
> I have a JavaScript app that creates an IFRAME through DOM
> (createElement( 'IFRAME')) However, that IFRAME does not have any
> content
> yet.
>

and it won't until you assign the src value.
But thats weird. It must be possible to create an empty document and
fill it dynamically, right? Else I'll have to do

iframe.src='abo ut:blank';


iframe.src = 'blank.html';


But thats still not very neat. I mean, its not logical to first have to
load an external html file inorder to dynamically create one? Shouldn't
something like

iframe.contentD ocument = new Document(those nice W3C things);

or

iframe.createCo ntentDocument(t hose nice W3C things);

work/be implemented?

Vincent

IE thinks about:blank is a security risk when loading the main page
using https, and causes mixed mode warnings.

I've used

iframe.src = "javascript:par ent.blank()"

to get around this. Where in the main window, you have a function

function blank()
{
return "<html></html>";
}

Again, it's ugly, but it works *now.*

Nige

Jul 23 '05 #6
On Sat, 3 Jul 2004 10:38:35 +0000 (UTC), ExGuardianReade r
<no***@noway.co m> wrote:
iframe.src = "javascript:par ent.blank()"


Recently I've had security problems with this too on cross window
iframe references in IE5.5sp2 fully patched. load a blank html doc
from your domain.

Jim.
--
comp.lang.javas cript FAQ - http://jibbering.com/faq/

Jul 23 '05 #7
DU
Vincent van Beveren wrote:
> I have a JavaScript app that creates an IFRAME through DOM
> (createElement( 'IFRAME')) However, that IFRAME does not have any
> content
> yet.
>

and it won't until you assign the src value.
But thats weird. It must be possible to create an empty document and
fill it dynamically, right? Else I'll have to do

iframe.src='abo ut:blank';


iframe.src = 'blank.html';


But thats still not very neat. I mean, its not logical to first have to
load an external html file inorder to dynamically create one? Shouldn't
something like

iframe.contentD ocument = new Document(those nice W3C things);

or

iframe.createCo ntentDocument(t hose nice W3C things);

work/be implemented?

Vincent


You have a good question here, I'd say. Apparently, you should be able
to do that but I have not found a single example of working code
anywhere and I tried my own and never could achieve anything despite
following thoroughly all documentations.

createDocument
http://www.w3.org/TR/2000/REC-DOM-Le...createDocument

E.g.:

var PopupDoctype = document.implem entation.create DocumentType("" ,
"!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN'",
"http://www.w3.org/TR/html4/strict.dtd");
var PopupDOMDocumen t = document.implem entation.create Document("",
"html", PopupDoctype);
PopupDOMDocumen t.title = "title here";
var objPopupBody = PopupDOMDocumen t.createElement ("body");
etc..

If you can't use that (I couldn't achieve results in any browsers), then
just use an "about:blan k" document and populate it dynamically. That
will work in many browsers. I have working examples on this.

There's also
createDocumentF ragment
http://www.w3.org/TR/2000/REC-DOM-Le...ml#ID-35CB04B5
"DocumentFragme nt is a "lightweigh t" or "minimal" Document object."
http://www.w3.org/TR/2000/REC-DOM-Le...ml#ID-B63ED1A3

DU
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3090
by: MC | last post by:
Hi to all, I would like to use in a XSL stylesheet an array variable which is defined in a Java program. For example, in my program, i defined a tab variable String tab = {"first", "second", "third"}; which i pass to the XSLT processor like this : transform.setParameter("tab", tab);
4
3296
by: Catherine Lynn Smith | last post by:
OK, I am learning my way around the new DOM, but I am still at a loss on finding a few things. I have an HTML document that links to a stylesheet. /* START STYLESHEET EXAMPLE */ /* styles/mystyles.css */ ..leftnav { font-family: Arial, Helvetica, sans-serif; font-size: 13pt;
3
1683
by: Jim Ley | last post by:
Hi, IE has the ability to setExpressions on stylesheets so you can calculate the value of the css property through script. For various reasons I'm wanting to use a side-effect of this to attach an event to every element of a class in a document (I'm including content from a lot of large 3rd party content, and iterating over the entire DOM searching for the classes and then attaching the event is proving too slow, aswell as being too...
7
2041
by: stefano | last post by:
Hi all, I hopen a new empty window from js code: var win = window.open("","debug","width=500,height=300,modal,dialog,resizable"); and I add some element to the new window: win.document.write("&lt;img src="image.gif&gt;"); win.document.write..... How can I add the stylesheet information of the file x.css (how and where I must write in the new window the line: <?xml-stylesheet href="x.css" type="text/css"?> )
3
5157
by: 2good2b | last post by:
Is there a way to change the background color dynamically, when the color is defined at a CSS stylesheet? (tried document.bgcolor and this.style.background-color) Thanks
0
7929
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8228
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8357
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6634
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5729
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3847
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2372
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1459
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.