473,511 Members | 14,981 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.contentWindow.document.documentElemen t)

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.contentWindow).

eLink = win.document.createElement("LINK");
eLink.setAttribute("REL","stylesheet");
eLink.setAttribute("HREF", GUIstyleSheet);
eLink.setAttribute("TYPE","text/css");
win.document.documentElement.appendChild(eLink);

But this:

win.document.open();
win.document.writeln("<HTML><HEAD>");
win.document.writeln("<LINK REL=\"stylesheet\"
HREF=\""+GUIstyleSheet+"\" TYPE=\"text/css\">");
win.document.writeln("</HEAD><BODY></BODY></HTML>");
win.document.close();

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

Thanks!
Vincent

Jul 23 '05 #1
7 2684
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.contentWindow.document.documentElemen t)

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.contentWindow).

eLink = win.document.createElement("LINK");
eLink.setAttribute("REL","stylesheet");
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.setAttribute("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.setAttribute("TYPE","text/css");
eLink.type = "text\/css";
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-32498296
win.document.documentElement.appendChild(eLink);

win.document.head.appendChild(eLink);

DU
But this:

win.document.open();
win.document.writeln("<HTML><HEAD>");
win.document.writeln("<LINK REL=\"stylesheet\"
HREF=\""+GUIstyleSheet+"\" TYPE=\"text/css\">");
win.document.writeln("</HEAD><BODY></BODY></HTML>");
win.document.close();

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='about: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='about: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.javascript 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='about: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.contentDocument = new Document(those nice W3C things);

or

iframe.createContentDocument(those 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='about: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.contentDocument = new Document(those nice W3C things);

or

iframe.createContentDocument(those 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:parent.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), ExGuardianReader
<no***@noway.com> wrote:
iframe.src = "javascript:parent.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.javascript 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='about: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.contentDocument = new Document(those nice W3C things);

or

iframe.createContentDocument(those 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.implementation.createDocumentType("",
"!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN'",
"http://www.w3.org/TR/html4/strict.dtd");
var PopupDOMDocument = document.implementation.createDocument("",
"html", PopupDoctype);
PopupDOMDocument.title = "title here";
var objPopupBody = PopupDOMDocument.createElement("body");
etc..

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

There's also
createDocumentFragment
http://www.w3.org/TR/2000/REC-DOM-Le...ml#ID-35CB04B5
"DocumentFragment is a "lightweight" 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
3077
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",...
4
3287
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 */ /*...
3
1669
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...
7
2035
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:...
3
5144
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
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7417
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...
1
7074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4734
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...
0
3219
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...
0
1572
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 ...
1
780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
445
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.