Window and iframe question

L

Logos

Tyler,

Cold Fusion 8 uses lots of open source javascript packages including
Ext, YUI etc. hence, the page in question loading tons of javascript
code from these freebies, hence, it did not make sense to copy over
and paste zillion line of these js code here... but points well taken
and you guys are absolutely right. FF's extension Firebug seems a
great debugging tool, with it, now I've identified some problems.

The web developer toolbar and aardvark are also godsends - you might
want to snag them if you aren't using them already.

Just as an FYI, if you need to post tons of code it's often handy to
put up a dummy page on your server somewhere and post a link to it (I
do that, anyway, and *I* think it's handy!)
 
L

Logos

Your link works. The technique of setting iframe.src = 'a dynamic
data set' also works as simple page (tested with IE7). The thing that
is killing me is that, when I embed the javascript code inside the
middle of an appliation page it failed to be called/executed. I
understand the standard way to add js functions is to place them in
the HTML head section, however, I have to bypass this rule for this
case. Also, some one even suggested to place js the bottom of a page,
which seems to suggest, js can be anywhere and I use inline short js
command in the middle of nowhere all the time.

From the execution block of your code and such difficulty I encounter
(which shouldn't), I tend to draw a conclusion that some javascript
kitty might be messing around my box, what do you think?

Thanks.

Are the functions you're including in the HTML block straight code
between <script> tags, or is it a link to an exterior file? If the
former, than I am puzzled. If the latter, the files won't load
properly if you place links to them in the body.

Tyler
 
D

Don Li

Tyler,

Please see my comments below. Thanks.

Don
Are the functions you're including in the HTML block straight code
between <script> tags, or is it a link to an exterior file?  
Sorry I don't understand very clearly of your above question. Are you
saying? Does the "top code" include plain HTML code or something else
like lots of javascripts?

then your "bottom code" ...?

If we're on the same page with this, then, the "top code" includes
tons of open source javascripts.

Now, here's another fact, with the same code structure/layout,
FckEditor, works. The problem I have with it is that it's way too
bloated for my need (I only need 5 to 7ish editing features), why
should I load its 523 files spanning across 72 folders (nuts for
efficiency if you ask me). And this editor slows down my app by more
than 50% (probably the editor would fit others' need though).

Thanks.

Don
P.S.
On your "if you need to post tons of code it's often handy to
put up a dummy page on your server somewhere and post a link to it (I
do that, anyway, and *I* think it's handy!)

My app is in beta, I don't feel comfortable to release its root IP
address (security concern is one thing, before release I'll beef up
security as well...)
 
V

VK

http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/ddaf4c98dc548f01?hl=en#



Sorry for lack of clarity. The <PROBLEM AREA/> is supposed to entail
the following test code:
--------------------------------
main page
<form id="nutsFrm" method="post">
<iframe name="out" id="out" src="Untitled1.html"
contenteditable="true" style="width:300px; height:150px"></iframe><br/

</form>

<form id="nutsFrm2" method="post">
<iframe name="nuts2" id="nuts2" style="width:300px; height:150px"></
iframe><br/>
</form>
--------------------------------

If I use simple other language's equivalent of "include" then it would
work (both your method and mine), however, it would LOSE the benefit
of very impressive presentation that is provided by a specific
function called CFWINDOW here (this app is literally sits inside it).
Hence, I'm caught in a very difficult situation...

Sorry for a delay in answering, I had to be out of town for some time.
I hope you have managed to solve your problem by now. If not yet then:

OK, the second option with iframe w/o src will simply not work: noop,
even if the most beautiful presentation in the world would be in
danger. So let's concentrate on what may work somehow.
Now a related question, other than setting iframe's designMode to
"On", is there another way that would allow similar function, that is,
WYSIWYG editing?

Firefox 3 will finally adopt contenteditable attribute but it doesn't
help too much right now. I am still not clear what does exactly happen
with your iframes after page load but if you need to set them ASAP to
contenteditable then try this trick:

<iframe name="out" id="out"
src="blank.html" contenteditable="true"
onload="document.frames['out001'].document.designMode='on';"
style="width:300px; height:150px"></iframe>

Please note that because of race conditions we don't use any "this"
reference in the event handler, otherwise iframe gets loaded before
the mother page does and you'll get run-time error; so we are going
indirectly over document.frames collection which gets created and
updated dynamically even before the mother page fully loaded. It is
not a documented behavior - actually it is a risky convenience added
against the documented requirements. However widely it is exposed
across UAs: you still better check your solution after each major
release of Firefox and IE.

If at the moment of the initial page load you already know what
initial URL for iframe do you need then sure use it:

<iframe name="out" id="out"
src="http://www.example.com/cgi-bin/my.cgi?etc"
contenteditable="true"
onload="document.frames['out001'].document.designMode='on';"
style="width:300px; height:150px"></iframe>

If at the moment of the initial page load you don't know what initial
URL for iframe do you need but some script loaded above this point and
not deferred may know it: then use document.write. Say if you have
somewhere among external scripts getUrlForIframe(name) function then
it could be:

<script>
(function() {
// set frameName properly:
var frameName = 'out001';
// end of user settings
document.write(''.concat(
'<iframe name="',frameName,'" id="',frameName,'" ',
'src="',getUrlForIframe(frameName),'" ',
'contenteditable="true" ',
'onload="self.frames[\'',frameName,'\'].document.designMode=\'on\';"
',
'style="width:300px; height:150px"></iframe>'));
})();
</script>

and so goes then for all involved frames, respectively changing
frameName for each block. Because it is a streight input stream before
page load, don't you even think :) to use "this" or "getElementById"
for getUrlForIframe calls: only hardcoded string literals.

Anonymous function wrapper is only to keep frameName and other
possible vars as local so do not pollute the global scope, if you
don't care then you may drop it for simplicity.
 
D

Don Li

http://groups.google.com/group/comp.lang.javascript/browse_frm/thread...

Sorry for lack of clarity.  The <PROBLEM AREA/> is supposed to entail
the following test code:
--------------------------------
main page
<form id="nutsFrm" method="post">
<iframe name="out" id="out" src="Untitled1.html"
contenteditable="true" style="width:300px; height:150px"></iframe><br/

<form id="nutsFrm2" method="post">
<iframe name="nuts2" id="nuts2" style="width:300px; height:150px"></
iframe><br/>
</form>
--------------------------------
If I use simple other language's equivalent of "include" then it would
work (both your method and mine), however, it would LOSE the benefit
of very impressive presentation that is provided by a specific
function called CFWINDOW here (this app is literally sits inside it).
Hence, I'm caught in a very difficult situation...

Sorry for a delay in answering, I had to be out of town for some time.
I hope you have managed to solve your problem by now. If not yet then:

OK, the second option with iframe w/o src will simply not work: noop,
even if the most beautiful presentation in the world would be  in
danger. So let's concentrate on what may work somehow.
Now a related question, other than setting iframe's designMode to
"On", is there another way that would allow similar function, that is,
WYSIWYG editing?

Firefox 3 will finally adopt contenteditable attribute but it doesn't
help too much right now. I am still not clear what does exactly happen
with your iframes after page load but if you need to set them ASAP to
contenteditable then try this trick:

<iframe name="out" id="out"
 src="blank.html" contenteditable="true"
 onload="document.frames['out001'].document.designMode='on';"
 style="width:300px; height:150px"></iframe>

Please note that because of race conditions we don't use any "this"
reference in the event handler, otherwise iframe gets loaded before
the mother page does and you'll get run-time error; so we are going
indirectly over document.frames collection which gets created and
updated dynamically even before the mother page fully loaded. It is
not a documented behavior - actually it is a risky convenience added
against the documented requirements. However widely it is exposed
across UAs: you still better check your solution after each major
release of Firefox and IE.

If at the moment of the initial page load you already know what
initial URL for iframe do you need then sure use it:

<iframe name="out" id="out"
 src="http://www.example.com/cgi-bin/my.cgi?etc"
 contenteditable="true"
 onload="document.frames['out001'].document.designMode='on';"
 style="width:300px; height:150px"></iframe>

If at the moment of the initial page load you don't know what initial
URL for iframe do you need but some script loaded above this point and
not deferred may know it: then use document.write. Say if you have
somewhere among external scripts getUrlForIframe(name) function then
it could be:

<script>
(function() {
 // set frameName properly:
 var frameName = 'out001';
 // end of user settings
 document.write(''.concat(
 '<iframe name="',frameName,'" id="',frameName,'" ',
 'src="',getUrlForIframe(frameName),'" ',
 'contenteditable="true" ',
 'onload="self.frames[\'',frameName,'\'].document.designMode=\'on\';"
',
 'style="width:300px; height:150px"></iframe>'));})();

</script>

and so goes then for all involved frames, respectively changing
frameName for each block. Because it is a streight input stream before
page load, don't you even think :) to use "this" or "getElementById"
for getUrlForIframe calls: only hardcoded string literals.

Anonymous function wrapper is only to keep frameName and other
possible vars as local so do not pollute the global scope, if you
don't care then you may drop it for simplicity.- Hide quoted text -

- Show quoted text -

Thank you so very much. Very quick question, on your
<iframe name="out" id="out"
src="blank.html" contenteditable="true"
onload="document.frames['out001'].document.designMode='on';"
style="width:300px; height:150px"></iframe>

Is the "onload" attribute supported by IE6/7 and FireFox2?
Also, this iframe is named and IDed as "out", how come you reference
it as "out001" in the
"document.frames['out001'].document.designMode='on';"?
 
V

VK

Sorry for a delay in answering, I had to be out of town for some time.
I hope you have managed to solve your problem by now. If not yet then:
OK, the second option with iframe w/o src will simply not work: noop,
even if the most beautiful presentation in the world would be in
danger. So let's concentrate on what may work somehow.
Firefox 3 will finally adopt contenteditable attribute but it doesn't
help too much right now. I am still not clear what does exactly happen
with your iframes after page load but if you need to set them ASAP to
contenteditable then try this trick:
<iframe name="out" id="out"
src="blank.html" contenteditable="true"
onload="document.frames['out001'].document.designMode='on';"
style="width:300px; height:150px"></iframe>
Please note that because of race conditions we don't use any "this"
reference in the event handler, otherwise iframe gets loaded before
the mother page does and you'll get run-time error; so we are going
indirectly over document.frames collection which gets created and
updated dynamically even before the mother page fully loaded. It is
not a documented behavior - actually it is a risky convenience added
against the documented requirements. However widely it is exposed
across UAs: you still better check your solution after each major
release of Firefox and IE.
If at the moment of the initial page load you already know what
initial URL for iframe do you need then sure use it:
<iframe name="out" id="out"
src="http://www.example.com/cgi-bin/my.cgi?etc"
contenteditable="true"
onload="document.frames['out001'].document.designMode='on';"
style="width:300px; height:150px"></iframe>
If at the moment of the initial page load you don't know what initial
URL for iframe do you need but some script loaded above this point and
not deferred may know it: then use document.write. Say if you have
somewhere among external scripts getUrlForIframe(name) function then
it could be:
<script>
(function() {
// set frameName properly:
var frameName = 'out001';
// end of user settings
document.write(''.concat(
'<iframe name="',frameName,'" id="',frameName,'" ',
'src="',getUrlForIframe(frameName),'" ',
'contenteditable="true" ',
'onload="self.frames[\'',frameName,'\'].document.designMode=\'on\';"
',
'style="width:300px; height:150px"></iframe>'));})();
</script>

and so goes then for all involved frames, respectively changing
frameName for each block. Because it is a streight input stream before
page load, don't you even think :) to use "this" or "getElementById"
for getUrlForIframe calls: only hardcoded string literals.
Anonymous function wrapper is only to keep frameName and other
possible vars as local so do not pollute the global scope, if you
don't care then you may drop it for simplicity.- Hide quoted text -
- Show quoted text -

Thank you so very much. Very quick question, on your
<iframe name="out" id="out"
src="blank.html" contenteditable="true"
onload="document.frames['out001'].document.designMode='on';"
style="width:300px; height:150px"></iframe>

Is the "onload" attribute supported by IE6/7 and FireFox2?

It is definitely supported by IE6/7 and Firefox 2.x : this is where I
am testing on.
AFAIK it is also supported by all browsers ever adopted IE's IFRAME
element.
Also, this iframe is named and IDed as "out", how come you reference
it as "out001" in the
"document.frames['out001'].document.designMode='on';"?

Oops - a typo of course. Either "out" or "out001" but not both.
 
D

Don Li

Thank you so very much.  Very quick question, on your
<iframe name="out" id="out"
 src="blank.html" contenteditable="true"
 onload="document.frames['out001'].document.designMode='on';"
 style="width:300px; height:150px"></iframe>
Is the "onload" attribute supported by IE6/7 and FireFox2?

It is definitely supported by IE6/7 and Firefox 2.x : this is where I
am testing on.
AFAIK it is also supported by all browsers ever adopted IE's IFRAME
element.
Also, this iframe is named and IDed as "out", how come you reference
it as "out001" in the
"document.frames['out001'].document.designMode='on';"?

Oops - a typo of course. Either "out" or "out001" but not both.- Hide quoted text -

- Show quoted text -

Thank you very much, I'll re-read and try your method ... and let you
know result.
 
D

Don Li

Thank you so very much.  Very quick question, on your
<iframe name="out" id="out"
 src="blank.html" contenteditable="true"
 onload="document.frames['out001'].document.designMode='on';"
 style="width:300px; height:150px"></iframe>
Is the "onload" attribute supported by IE6/7 and FireFox2?
It is definitely supported by IE6/7 and Firefox 2.x : this is where I
am testing on.
AFAIK it is also supported by all browsers ever adopted IE's IFRAME
element.
Also, this iframe is named and IDed as "out", how come you reference
it as "out001" in the
"document.frames['out001'].document.designMode='on';"?
Oops - a typo of course. Either "out" or "out001" but not both.- Hide quoted text -
- Show quoted text -

Thank you very much, I'll re-read and try your method ... and let you
know result.- Hide quoted text -

- Show quoted text -

Ok, I just tried it with IE7 and FF2. First, promising progress, I
use your following technique and expand it a bit (may not be for the
unintiated... :)
<iframe name="out" id="out"
src="blank.html" contenteditable="true"
onload="document.frames['out'].document.designMode='on';"
style="width:300px; height:150px"></iframe>

I got a js err w/ msg of "stack overflow at line 0" upon loading two
test iframes, but the value of your initial sample of "Hello" did show
up in the iframe according to your design and it is EDITABLE, man, it
made me feel good, thank you a million, so, how can we possibly get
rid of the 'stack overflow...' sucker (sorry for the language)?

Don
 
V

VK

Thank you so very much. Very quick question, on your
<iframe name="out" id="out"
src="blank.html" contenteditable="true"
onload="document.frames['out001'].document.designMode='on';"
style="width:300px; height:150px"></iframe>
Is the "onload" attribute supported by IE6/7 and FireFox2?
It is definitely supported by IE6/7 and Firefox 2.x : this is where I
am testing on.
AFAIK it is also supported by all browsers ever adopted IE's IFRAME
element.
Also, this iframe is named and IDed as "out", how come you reference
it as "out001" in the
"document.frames['out001'].document.designMode='on';"?
Oops - a typo of course. Either "out" or "out001" but not both.- Hide quoted text -
- Show quoted text -
Thank you very much, I'll re-read and try your method ... and let you
know result.- Hide quoted text -
- Show quoted text -

Ok, I just tried it with IE7 and FF2. First, promising progress, I
use your following technique and expand it a bit (may not be for the
unintiated... :)
<iframe name="out" id="out"
src="blank.html" contenteditable="true"
onload="document.frames['out'].document.designMode='on';"
style="width:300px; height:150px"></iframe>

I got a js err w/ msg of "stack overflow at line 0" upon loading two
test iframes, but the value of your initial sample of "Hello" did show
up in the iframe according to your design and it is EDITABLE, man, it
made me feel good, thank you a million, so, how can we possibly get
rid of the 'stack overflow...' sucker (sorry for the language)?

Don

"stack overflow at line 0" debugging over a verbal problem
description, w/o source analyzing? Uhm... OK, but I wash my hands
twice from everything before that :)

Assuming added blocks caused it:

1) Did you ensure that each iframe has unique name/id pair:
iframe name="out001" id="out001"
onload="document.frames['out001'].document.designMode='on';"
iframe name="out002" id="out002"
onload="document.frames['out002'].document.designMode='on';"
iframe name="out003" id="out003"
onload="document.frames['out003'].document.designMode='on';"
etc. ?

2) Very unlikely to be the reason but let's prevent multiple property
set for designMode.

So the final block out of three iframes to insert for testing into
your div would be:

<iframe name="out001" id="out001"
src="blank.html" contenteditable="true"
onload="
if(document.frames['out001'].document.designMode!='on') {
document.frames['out001'].document.designMode!='on';
}"
style="width:300px; height:150px"></iframe>
<iframe name="out002" id="out002"
src="blank.html" contenteditable="true"
onload="
if(document.frames['out002'].document.designMode!='on') {
document.frames['out002'].document.designMode!='on';
}"
style="width:300px; height:150px"></iframe>
<iframe name="out003" id="out003"
src="blank.html" contenteditable="true"
onload="
if(document.frames['out003'].document.designMode!='on') {
document.frames['out003'].document.designMode!='on';
}"
style="width:300px; height:150px"></iframe>
 
D

Don Li

"stack overflow at line 0" debugging over a verbal problem
description, w/o source analyzing? Uhm... OK, but I wash my hands
twice from everything before that :)

Assuming added blocks caused it:

1) Did you ensure that each iframe has unique name/id pair:
iframe name="out001" id="out001"
 onload="document.frames['out001'].document.designMode='on';"
iframe name="out002" id="out002"
 onload="document.frames['out002'].document.designMode='on';"
iframe name="out003" id="out003"
 onload="document.frames['out003'].document.designMode='on';"
etc. ?

2) Very unlikely to be the reason but let's prevent multiple property
set for designMode.

So the final block out of three iframes to insert for testing into
your div would be:

<iframe name="out001" id="out001"
 src="blank.html" contenteditable="true"
 onload="
 if(document.frames['out001'].document.designMode!='on') {
  document.frames['out001'].document.designMode!='on';
 }"
 style="width:300px; height:150px"></iframe>
<iframe name="out002" id="out002"
 src="blank.html" contenteditable="true"
 onload="
 if(document.frames['out002'].document.designMode!='on') {
  document.frames['out002'].document.designMode!='on';
 }"
 style="width:300px; height:150px"></iframe>
<iframe name="out003" id="out003"
 src="blank.html" contenteditable="true"
 onload="
 if(document.frames['out003'].document.designMode!='on') {
  document.frames['out003'].document.designMode!='on';
 }"
 style="width:300px; height:150px"></iframe>- Hide quoted text -

- Show quoted text -

Ok, here's what I did (I admit I tried to be clever...)
Within the DIV, I have the following:

<iframe name="txt1" id="notes1" src="Untitled1.html"
contenteditable="true"
onload="document.frames['txt1'].document.designMode='on';var doc =
self.frames['txt1'].document;self.frames['txt1'].document;doc.clear();doc.open('text/
html','replace');doc.write('<html><body>Hello!</body></
html>');doc.close();"
contentEditable="true" style="width:300px; height:150px"></
iframe><br/>

then, the following iframe too // not meaningful for this test
purpose.

<form id="nutsFrm2" method="post">
<iframe name="nuts2" id="nuts2"
onload="document.frames['nuts2'].document.designMode='on';"
style="width:300px; height:150px"></iframe><br/>
</form>

-------------
So, it looks like the "onload" attribute has limitation on how many
{statements} it supports. And if I move these {statements} to a
separate function and no matter where I put it, top of the page or
bottom, the page would complain that the iframe object or the like not
found or defined...
Catch 22?

Thank you a ton.
 
V

VK

On Mar 26, 10:52 pm, Don Li <[email protected]> wrote:
"stack overflow at line 0" debugging over a verbal problem
description, w/o source analyzing? Uhm... OK, but I wash my hands
twice from everything before that :)
Assuming added blocks caused it:
1) Did you ensure that each iframe has unique name/id pair:
iframe name="out001" id="out001"
onload="document.frames['out001'].document.designMode='on';"
iframe name="out002" id="out002"
onload="document.frames['out002'].document.designMode='on';"
iframe name="out003" id="out003"
onload="document.frames['out003'].document.designMode='on';"
etc. ?
2) Very unlikely to be the reason but let's prevent multiple property
set for designMode.
So the final block out of three iframes to insert for testing into
your div would be:
<iframe name="out001" id="out001"
src="blank.html" contenteditable="true"
onload="
if(document.frames['out001'].document.designMode!='on') {
document.frames['out001'].document.designMode!='on';
}"
style="width:300px; height:150px"></iframe>
<iframe name="out002" id="out002"
src="blank.html" contenteditable="true"
onload="
if(document.frames['out002'].document.designMode!='on') {
document.frames['out002'].document.designMode!='on';
}"
style="width:300px; height:150px"></iframe>
<iframe name="out003" id="out003"
src="blank.html" contenteditable="true"
onload="
if(document.frames['out003'].document.designMode!='on') {
document.frames['out003'].document.designMode!='on';
}"
style="width:300px; height:150px"></iframe>- Hide quoted text -
- Show quoted text -

Ok, here's what I did (I admit I tried to be clever...)
Within the DIV, I have the following:

<iframe name="txt1" id="notes1" src="Untitled1.html"
contenteditable="true"
onload="document.frames['txt1'].document.designMode='on';var doc =
self.frames['txt1'].document;self.frames['txt1'].document;doc.clear();doc.open('text/
html','replace');doc.write('<html><body>Hello!</body></
html>');doc.close();"
contentEditable="true" style="width:300px; height:150px"></
iframe><br/>

then, the following iframe too // not meaningful for this test
purpose.

<form id="nutsFrm2" method="post">
<iframe name="nuts2" id="nuts2"
onload="document.frames['nuts2'].document.designMode='on';"
style="width:300px; height:150px"></iframe><br/>
</form>

It doesn't. But anything before "document.load" event is left for
developers' peculiarities and we are currently exploring the most
obscure of them. I normally do not go into that quagmire but... it
just puzzled me somehow. So I could repro your "stack overflow line:0"
and it is exactly what we had that summer 1998 between layer and
iframe. We dealt with that, I just need a bit of retro. A race
condition between load event and document.write to fix ...
I need some time.
 
D

Don Li

<form id="nutsFrm2" method="post">
<iframe name="nuts2" id="nuts2"
onload="document.frames['nuts2'].document.designMode='on';"
style="width:300px; height:150px"></iframe><br/>
</form>

It doesn't. But anything before "document.load" event is left for
developers' peculiarities and we are currently exploring the most
obscure of them. I normally do not go into that quagmire but... it
just puzzled me somehow. So I could repro your "stack overflow line:0"
and it is exactly what we had that summer 1998 between layer and
iframe. We dealt with that, I just need a bit of retro. A race
condition between load event and document.write to fix ...
I need some time.- Hide quoted text -

- Show quoted text -

Thank you very much for the update...
 
V

VK

<form id="nutsFrm2" method="post">
<iframename="nuts2" id="nuts2"
onload="document.frames['nuts2'].document.designMode='on';"
style="width:300px; height:150px"></iframe><br/>
</form>
It doesn't. But anything before "document.load" event is left for
developers' peculiarities and we are currently exploring the most
obscure of them. I normally do not go into that quagmire but... it
just puzzled me somehow. So I could repro your "stack overflow line:0"
and it is exactly what we had that summer 1998 between layer and
iframe. We dealt with that, I just need a bit of retro. A race
condition between load event and document.write to fix ...
I need some time.- Hide quoted text -
- Show quoted text -

Thank you very much for the update...

1. Initial SRC attribute value for IFRAME
The current URL for SRC defines current cross-domain security policy
for the given pages. Because of that it is not allowed to skip this
attribute even if IFRAME will be used only for dynamically generated
content. A failure to do so will lead to IFRAME run-time scripting
access block. It was true at least for NN4.x/IE4.x/IE5.x
AFAICT at least IE 6.x and Firefox 2.x do allow to skip SRC attribute:
in such case it is being automatically set to the virtual about:blank
page. Anyone is free to use this added convenience but I humbly stay
on the old path. First of all I don't like to torture an engine
without an explicit necessity - even if it is allowed by engine
makers. Secondly a number of spyware and hijacking exploits are using
about: internal URI scheme and the common habit to set about:blank as
the browser's home and/or startup page; therefore many anti-spyware
and anti-hijacking tools are implementing special treatment for
windows and (i)frames with about:blank address up to blocking such
content completely or by blocking scripted access to them. In summary
anyone is free to relay on SRC being set automatically and working
properly: but this option is not considered and not advised by myself.

This way for iframes used as containers for dynamic content - and not
to display physical documents - still initial SRC attribute is always
being set and pointing to a physical document located in the same
domain and subdomain as the mother page to compile with the cross-
domain security requirements.

Such document should be some minimalistic blank HTML document. The
exact suggested content could be:

<html><head><title></title></head><body bgcolor="#FFFFFF"><p>&nbsp;</
p></body></html>

See: http://www.russiancourses.org/tmp/blank.html

It is based two practical considerations:

1) A document with no content at all in its body section confuses
Firefox if switched to designMode: the initial cursor position will be
set to the upper-right corner as if dir would be right-to-left, but it
gets corrected with the first typed symbol. Obviously it looks very
confusing for end-users. Therefore we are using a paragraph with non-
breaking space in it to fix this behavior.
2) By default IFRAME in Firefox is transparent and in IE is opaque.
That means that the content behind IFRAME will be visible in Firefox.
It may be what you want but most of the time it is not. This is why we
are explicitly setting bgcolor for body.
A note for purists if they are wondering why do not use CSS background-
color instead and stay Strict? First of all it is textually longer and
we want to be as short as possible; and the last but not the least:
hey, we are prepearing to work with IFRAMEs so what Strict are you
talking about? IFRAMEs are not a part of Strict DTD.

2. IFRAME as an editable container
In all samples blank.html assumed to have the exact content as
suggested in the section 1.
All methods are tested on Windows XP SP2 with
Internet Explorer 6.0
Internet Explorer 7.0
Mozilla Firefox 2.0.0.13
Opera 9.26
Safari 3.0.4

A note for purists: DTDs from W3C are missing ONLOAD attribute for
IFRAME in all HTML DTDs. It is a simple typo to disregard: any browser
ever implemented IFRAME also supports documented on MSDN onload event
handler. At the same time W3C Validator will obviously complain.
Either disregard it or use document.write in SCRIPT block to insert
your iframes. Here I am using the first decision.

Option 1 : We just need an empty IFRAME with editing mode being turned
on by default.

<iframe
name="doc01"
src="blank.html"
onload="
(function(){
var name = 'doc01';
try {
var doc = self.frames[name].document;
}
catch (SecurityException) {
/*NOP*/
}
if ((doc) && ('designMode' in doc)) {
doc.designMode = 'on';
}
})();"></iframe>

Add as reasonably many IFRAMEs as you need: just don't forget to
change "name" and var b\name in each block.

See: http://www.russiancourses.org/tmp/Option1.html

Option 2 : We need to load a document into IFRAME with editing mode
being turned on by default.
Same as Option 1, just use the right src value. Same domain security
rule applies of course, so you can do it only with documents from the
same domain and the same subdomain.

See: http://www.russiancourses.org/tmp/Option2.html

Option 3. We need to load a document into IFRAME with editing mode
being turned on by default. SRC attribute cannot be hardcoded and it
will set on page load. In the sample it is assumed that some of
preliminary loaded scripts has function getUrlForIframe that takes
string argument with the name of iframe and returns src value for that
iframe.

Unfortunately I couldn't find a solution for this option. The sample
code seemingly works for a single iframe, but after that no other
script block is being executed. The function is being executed without
runtime errors as window.alert shows, but any other script is simply
disregarded. The most weird behavior - or maybe I am missing something
obvious. Any feedback is highly appreciated.

See: http://www.russiancourses.org/tmp/Option3.html

Option 4. We need an IFRAME with editing mode being turned on by
default and pre-filled wth some content generated by script.
In the sample it is assumed that some of preliminary loaded scripts
has function getContentForIframe that takes string argument with the
name of iframe and returns HTML code to write into iframe. The only
cross-browser reliable solution I know is to split the task between
IFRAME and SCRIPT blocks. Anything else leads to unhandled race
condition and to "too many recursions" runtime error.

<iframe
name="doc01"
src="blank.html"></iframe
var name = 'doc01';
var doc = self.frames[name].document;
if (doc) {
doc.open('text/html','replace');
doc.write(getContentForIframe(name));
doc.close();
if ('designMode' in doc) {
doc.designMode = 'on';
}
}
</script>

See: http://www.russiancourses.org/tmp/Option4.html
 
V

VK

Option 3. We need to load a document into IFRAME with editing mode
being turned on by default. SRC attribute cannot be hardcoded and it
will set on page load. In the sample it is assumed that some of
preliminary loaded scripts has function getUrlForIframe that takes
string argument with the name of iframe and returns src value for that
iframe.

Unfortunately I couldn't find a solution for this option. The sample
code seemingly works for a single iframe, but after that no other
script block is being executed. The function is being executed without
runtime errors as window.alert shows, but any other script is simply
disregarded. The most weird behavior - or maybe I am missing something
obvious. Any feedback is highly appreciated.

Lucky I have found the error right at the moment when I was starting
to loose the rest of my mind. How stupid I am: who will close IFRAME?!
I have forgotten to document.write the closing </iframe> tag so the
first IFRAME expanded to the rest of the page. Shame on me... Here the
corrected working version:

http://www.russiancourses.org/tmp/Option3_03_corrected.html
 
D

Don Li

First, let me say I'm deeply indebted to you. All the four options
that you so elegantly elaborated work, however, I'd prefer not to
generate doc01.html,doc02.html... docN.html beforehand . Here I'm
wondering if we can replace the content of the seed html file,
{blank.html} here in this case, on the fly, so, the supporting
javascript function would look like the following,
// my syntax isn't correct, but I don't know how...

function getContentForIframe(n) {
if (n=='doc01') {
replace('blank.html','<html><head><title></title></head><body
bgcolor=##FFFFFF><p>content 1</p></body></html>');
return 'blank.html';
}
if (n=='doc02') {
replace('blank.html','<html><head><title></title></head><body
bgcolor=##FFFFFF><p>content 2</p></body></html>');
return 'blank.html';
}

Is it feasible?

Also, option 4 isn't practical for my case because each script right
after each iframe have problem being executed under this application
server package.

Once again, I'd truly grateful.
Thank you very much for the update...

1. Initial SRC attribute value for IFRAME
The current URL for SRC defines current cross-domain security policy
for the given pages. Because of that it is not allowed to skip this
attribute even if IFRAME will be used only for dynamically generated
content. A failure to do so will lead to IFRAME run-time scripting
access block. It was true at least for NN4.x/IE4.x/IE5.x
AFAICT at least IE 6.x and Firefox 2.x do allow to skip SRC attribute:
in such case it is being automatically set to the virtual about:blank
page. Anyone is free to use this added convenience but I humbly stay
on the old path. First of all I don't like to torture an engine
without an explicit necessity - even if it is allowed by engine
makers. Secondly a number of spyware and hijacking exploits are using
about: internal URI scheme and the common habit to set about:blank as
the browser's home and/or startup page; therefore many anti-spyware
and anti-hijacking tools are implementing special treatment for
windows and (i)frames with about:blank address up to blocking such
content completely or by blocking scripted access to them. In summary
anyone is free to relay on SRC being set automatically and working
properly: but this option is not considered and not advised by myself.

This way for iframes used as containers for dynamic content - and not
to display physical documents - still initial SRC attribute is always
being set and pointing to a physical document located in the same
domain and subdomain as the mother page to compile with the cross-
domain security requirements.

Such document should be some minimalistic blank HTML document. The
exact suggested content could be:

<html><head><title></title></head><body bgcolor="#FFFFFF"><p> </
p></body></html>

See:http://www.russiancourses.org/tmp/blank.html

It is based two practical considerations:

1) A document with no content at all in its body section confuses
Firefox if switched to designMode: the initial cursor position will be
set to the upper-right corner as if dir would be right-to-left, but it
gets corrected with the first typed symbol. Obviously it looks very
confusing for end-users. Therefore we are using a paragraph with non-
breaking space in it to fix this behavior.
2) By default IFRAME in Firefox is transparent and in IE is opaque.
That means that the content behind IFRAME will be visible in Firefox.
It may be what you want but most of the time it is not. This is why we
are explicitly setting bgcolor for body.
A note for purists if they are wondering why do not use CSS background-
color instead and stay Strict? First of all it is textually longer and
we want to be as short as possible; and the last but not the least:
hey, we are prepearing to work with IFRAMEs so what Strict are you
talking about? IFRAMEs are not a part of Strict DTD.

2. IFRAME as an editable container
In all samples blank.html assumed to have the exact content as
suggested in the section 1.
All methods are tested on Windows XP SP2 with
Internet Explorer 6.0
Internet Explorer 7.0
Mozilla Firefox 2.0.0.13
Opera 9.26
Safari 3.0.4

A note for purists:  DTDs from W3C are missing ONLOAD attribute for
IFRAME in all HTML DTDs. It is a simple typo to disregard: any browser
ever implemented IFRAME also supports documented on MSDN onload event
handler. At the same time W3C Validator will obviously complain.
Either disregard it or use document.write in SCRIPT block to insert
your iframes. Here I am using the first decision.

Option 1 : We just need an empty IFRAME with editing mode being turned
on by default.

<iframe
 name="doc01"
 src="blank.html"
 onload="
 (function(){
 var name = 'doc01';
 try {
  var doc = self.frames[name].document;}

catch (SecurityException) {
 /*NOP*/}

 if ((doc) && ('designMode' in doc)) {
  doc.designMode = 'on';
 }
 })();"></iframe>

Add as reasonably many IFRAMEs as you need: just don't forget to
change "name" and var b\name in each block.

See:http://www.russiancourses.org/tmp/Option1.html

Option 2 : We need to load a document into IFRAME with editing mode
being turned on by default.
Same as Option 1, just use the right src value. Same domain security
rule applies of course, so you can do it only with documents from the
same domain and the same subdomain.

See:http://www.russiancourses.org/tmp/Option2.html

Option 3.  We need to load a document into IFRAME with editing mode
being turned on by default. SRC attribute cannot be hardcoded and it
will set on page load. In the sample it is assumed that some of
preliminary loaded scripts has function getUrlForIframe that takes
string argument with the name of iframe and returns src value for that
iframe.

Unfortunately I couldn't find a solution for this option. The sample
code seemingly works for a single iframe, but after that no other
script block is being executed. The function is being executed without
runtime errors as window.alert shows, but any other script is simply
disregarded. The most weird behavior - or maybe I am missing something
obvious. Any feedback is highly appreciated.

See:http://www.russiancourses.org/tmp/Option3.html

Option 4. We need an IFRAME with editing mode being turned on by
default and pre-filled wth some content generated by script.
In the sample it is assumed that some of preliminary loaded scripts
has function getContentForIframe that takes string argument with the
name of iframe and returns HTML code to write into iframe. The only
cross-browser reliable solution I know is to split the task between
IFRAME and SCRIPT blocks. Anything else leads to unhandled race
condition and to "too many recursions" runtime error.

<iframe
 name="doc01"
 src="blank.html"></iframe
 ><script>
var name = 'doc01';
var doc = self.frames[name].document;
if (doc) {
 doc.open('text/html','replace');
 doc.write(getContentForIframe(name));
 doc.close();
 if ('designMode' in doc) {
  doc.designMode = 'on';
 }}

</script>

See:http://www.russiancourses.org/tmp/Option4.html- Hide quoted text -

- Show quoted text -
 
V

VK

First, let me say I'm deeply indebted to you. All the four options
that you so elegantly elaborated work, however, I'd prefer not to
generate doc01.html,doc02.html... docN.html beforehand . Here I'm
wondering if we can replace the content of the seed html file,
{blank.html} here in this case, on the fly

Which is, by all means, the Option 4:

"Option 4. We need an IFRAME with editing mode being turned on by
default and pre-filled wth some content generated by script."

The "generated content" can be anything, from "Hello world!" to some
complex HTML page: whatever your getContentForIframe will return.
Also, option 4 isn't practical for my case because each script right
after each iframe have problem being executed under this application
server package.

The option 4 doesn't care what else scripts are placed into your page
as long as iframe/script blocks are placed properly where you need
them. Therefore I need more details about their problem of being
executed. Possibly I still do not understand properly the overall
structure of your document.
 
D

Don Li

Which is, by all means, the Option 4:

"Option 4. We need an IFRAME with editing mode being turned on by
default and pre-filled wth some content generated by script."

The "generated content" can be anything, from "Hello world!" to some
complex HTML page: whatever your getContentForIframe will return.



The option 4 doesn't care what else scripts are placed into your page
as long as iframe/script blocks are placed properly where you need
them. Therefore I need more details about their problem of being
executed. Possibly I still do not understand properly the overall
structure of your document.

Sorry, because the weirdness of the app server package that uses some
open source software (not that they are not good but they naturally
requires load sequence etc...).

So, as a workaround, I now have two levels of templates:
top level: include javascripts (they would be loaded)
detail level: better not to load javascript files here (for they have
loading problems), but
at this level, all the iframes reside.

So, if we can change the seed 'blank.html' file content on the fly at
the the top level, it would work as designed.
my following syntax isn't correct... thanks.

if (n=='doc01') {
var str = new String();
str.replace('blank.html','<html><head><title></title></head><body
bgcolor=##FFFFFF><p>Hello 1</p></body></html>');
return 'blank.html';
 
V

VK

First, let me say I'm deeply indebted to you. All the four options
Sorry, because the weirdness of the app server package that uses some
open source software (not that they are not good but they naturally
requires load sequence etc...).

So, as a workaround, I now have two levels of templates:
top level: include javascripts (they would be loaded)
detail level: better not to load javascript files here (for they have
loading problems), but
at this level, all the iframes reside.

Yes, but is it one HTML page as you once posted - however complex it
would be - or is a Ruby-on-Rails like "Matrioshka style" with a script
generating a script that generates a script that ... N ... generates
the content? I am not criticizing anything, I'm only asking for
clarity.
So, if we can change the seed 'blank.html' file content on the fly

You can't do it. The seed is the seed. As soon as you do the first
document.write into it after iframe load event, it has nothing to do
with blank.html anymore. It is just iframe container filled with
dynamically generated content. If you could move this part of the
logic to the server then you could use Option 3 instead: so for each
iframe an appropriate CGI request URL would be formed and server would
feed the necessary content.
For the option 4 (client-side content feeding over document.write) I
have posted the only working solution I know about - that doesn't mean
that there are not any others, I am just not aware of them.

The Option 5 could be stop trying to accomplish everything right
during the page load. Just wait for main document LOAD event and do
what you need using DOM methods. For your users you can put some nice
"Loading..." animation to keep them happy :)
 
D

Don Li

Yes, but is it one HTML page as you once posted - however complex it
would be - or is a Ruby-on-Rails like "Matrioshka style" with a script
generating a script that generates a script that ... N ... generates
the content? I am not criticizing anything, I'm only asking for
clarity.


You can't do it. The seed is the seed. As soon as you do the first
document.write into it after iframe load event, it has nothing to do
with blank.html anymore. It is just iframe container filled with
dynamically generated content. If you could move this part of the
logic to the server then you could use Option 3 instead: so for each
iframe an appropriate CGI request URL would be formed and server would
feed the necessary content.
For the option 4 (client-side content feeding over document.write) I
have posted the only working solution I know about - that doesn't mean
that there are not any others, I am just not aware of them.

The Option 5 could be stop trying to accomplish everything right
during the page load. Just wait for main document LOAD event and do
what you need using DOM methods. For your users you can put some nice
"Loading..." animation to keep them happy :)- Hide quoted text -

- Show quoted text -

My apologies for not responding on time. I'm wondering how difficult
it is to encapsulate the function as a tiny program, then using it as
an object ... the much disliked (by me or by me only for its bloated
features and naturally slow loading) fukeditor wysiwyg editor works
just like that. Care to consider to work with me on that, and maybe
"offline"?

Many thanks.
 

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,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top