473,770 Members | 4,718 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 2710
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
3106
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
3319
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
1693
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
2047
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
5180
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
9432
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10059
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...
1
7420
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
6682
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
5313
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...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3974
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
2
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2822
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.