469,303 Members | 1,879 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,303 developers. It's quick & easy.

Writing Text to web page in different frame

Hello all:

I have a page with two frames named "menu" and "display".
An event handler in "menu" changes the src attribute for
"display", resulting in a different page being loaded for
each choice in a option list.
I accomplish this as follows:
// .... code
var frameTag = top.document.getElementById("display");
var optionValue =
parseInt(listObject.options[listObject.selectedIndex].value);
// .... code for array of form names
frameTag["src"] = "short-forms/" + adForms[optionValue];
// and the target page is loaded in "display"

The goal is to write text into a font element in whichever page
is in the "display" frame. The font tag is configured as such:
<font id="prop_county_display" color="darkred">
&nbsp;
</font>
Replacing &nbsp; with the text.

I seem to referencing the font element with the following code:
var countyText =
top["display"].document.getElementById('prop_county_display');
//the following "output stub:
alert('countyText = ' + countyText + ' county: ' + chosenCounty);
//Tells me that I referenced an HTMLFontElement and the text is a
//valid string

The code for writing the text into the FontElement is as follows:
var res =
countyText.replaceChild(top["display"].document.createTextNode(chosenCounty),countyText. firstChild);
// and I test the return value as
alert('result: ' + res);
// which informs me: result: [object Text]

Sadly, no change is made to the target document.

Questions:
1)What am I doing wrong?
2)I have found frames to be a bit tricky, could it be that
this method is not the best?
cgi might work better, I'm certainly much more fluent with
cgi that javascript.

As always
Thanks
Tim
Jul 23 '05 #1
13 3397

Oh boy, haven't you heard that <span> or <div> and that Font is quite
deprecated, or of the .innerHTML property for an element object?
Danny
On Thu, 30 Jun 2005 12:57:39 -0700, Tim Johnson <ti*@johnsons-web.com>
wrote:

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 23 '05 #2
Danny wrote:

Oh boy, haven't you heard that <span> or <div> and that Font is
quite deprecated, or of the .innerHTML property for an element object?

Hi Danny:
Can you explain further please?
Thanks
Tim
Jul 23 '05 #3
Danny wrote:

Oh boy, haven't you heard that <span> or <div> and that Font is
quite deprecated, or of the .innerHTML property for an element object?

Danny: I did a quick google on .innerHTML The following link:
http://wsabstract.com/javatutors/dynamiccontent4.shtml

I understand from that URL that the .innerHTML property is deprecated by
both W3C and IE.

Regarding your reference to using <div> as a "placeholder" for dynamic
text (at least that's what I think you mean): This works for
the "original" page that is *originally* sourced by the the "display" frame.

But the kicker is that when I reload a new page into that frame, dynamic
rewrites are failing, and the example I gave is only one. Tested on
firefox and netscape in linux RH 9.0 ....

Tim
Jul 23 '05 #4
Tim Johnson wrote:
Danny wrote:

Oh boy, haven't you heard that <span> or <div> and that Font is
quite deprecated, or of the .innerHTML property for an element object?

Danny: I did a quick google on .innerHTML The following link:
http://wsabstract.com/javatutors/dynamiccontent4.shtml

I understand from that URL that the .innerHTML property is deprecated by
both W3C and IE.


I don't understand how anybody can say the W3C deprecated *anything* in
javascript since the W3C has nothing to do with scripting languages.
That is the area that ECMA covers. But even then, I find it hard to
believe that the ECMA would "deprecate" a feature that was never an ECMA
"feature" to start with.

Or, for that matter, that MS would deprecate *anything* it came up with.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #5
Randy Webb wrote:
Tim Johnson wrote:
Danny wrote:

Oh boy, haven't you heard that <span> or <div> and that Font is
quite deprecated, or of the .innerHTML property for an element object?

Danny: I did a quick google on .innerHTML The following link:
http://wsabstract.com/javatutors/dynamiccontent4.shtml

I understand from that URL that the .innerHTML property is deprecated
by both W3C and IE.

I don't understand how anybody can say the W3C deprecated *anything* in
javascript since the W3C has nothing to do with scripting languages.
That is the area that ECMA covers. But even then, I find it hard to
believe that the ECMA would "deprecate" a feature that was never an ECMA
"feature" to start with.

Or, for that matter, that MS would deprecate *anything* it came up with.


I'm only quoting what is stated in that page. Personally, all I give
a damn about is what works. Let us refocus on the problem:

Regardless of whether or not I use the .innerHTML method, regardless of
whether I use the associative approach or 'hard coded' attribute names,
here is the problem:

Using any of these methods, I *CAN* write to a page in a frame that is
loaded statically (the target of the hand - coded "src" attribute).

I *CAN'T* write to any page that is dynamically loaded by changing the
'src' attribute at the top level.

Please see my original posting.
-------------------------------

Thanks
Tim
Jul 23 '05 #6
Randy Webb wrote:
Tim Johnson wrote:
Danny wrote:

Oh boy, haven't you heard that <span> or <div> and that Font is
quite deprecated, or of the .innerHTML property for an element object?

Danny: I did a quick google on .innerHTML The following link:
http://wsabstract.com/javatutors/dynamiccontent4.shtml

I understand from that URL that the .innerHTML property is deprecated
by both W3C and IE.

I don't understand how anybody can say the W3C deprecated *anything* in
javascript since the W3C has nothing to do with scripting languages.
That is the area that ECMA covers. But even then, I find it hard to
believe that the ECMA would "deprecate" a feature that was never an ECMA
"feature" to start with.


You are failing to distinguish between ECMAScript/JavaScript, on the one
hand, and the DOM on the other. .innerHTML is part of the DOM, which is
very much W3C's business. Both .innerHTML and .write are very strongly
deprecated; in particular, they are not supported with XHTML at all.

(I have no idea about IE, especially since IE doesn't support XHTML in
the first place.)

--
John W. Kennedy
"Sweet, was Christ crucified to create this chat?"
-- Charles Williams. "Judgement at Chelmsford"
Jul 23 '05 #7


John W. Kennedy wrote:
You are failing to distinguish between ECMAScript/JavaScript, on the one
hand, and the DOM on the other. .innerHTML is part of the DOM, which is
very much W3C's business. Both .innerHTML and .write are very strongly
deprecated; in particular, they are not supported with XHTML at all.


Where does the W3C deprecate the write method? If browser producers
choose to not implement the write method for XHTML it does not mean the
W3C deprecates the method.

As for innerHTML it has never been part of the W3C DOM but your claim
that it is not supported in XHTML at all is not true, scripting support
in real XHTML pages (application/xhtml+xml) has been flaky and is still
not up to par with scripting of HTML pages (text/html) but Opera 8 for
instance already supports innerHTML in application/xhtml+xml documents
and Mozilla 1.8 nightly builds do support that too so support is there
or coming.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #8
Tim Johnson wrote:
Randy Webb wrote:
I'm only quoting what is stated in that page. Personally, all I give a
damn about is what works. Let us refocus on the problem:

Regardless of whether or not I use the .innerHTML method, regardless of
whether I use the associative approach or 'hard coded' attribute names,
here is the problem:

Using any of these methods, I *CAN* write to a page in a frame that is
loaded statically (the target of the hand - coded "src" attribute).

I *CAN'T* write to any page that is dynamically loaded by changing the
'src' attribute at the top level.

Please see my original posting.
-------------------------------


No solution appears readily available, either from my tests or
from this newsgroup. It seems not a good idea to first dynamically
load a page into a frame and then attempt to write to it from another.

the workaround is to use a cgi process dynamically generated for
the 'frame' tag "src" attribute. I get the results I want that way.

Javascript is a bit like tequila methinks. Used in small amounts,
adds something to the experience, but used to excess, can create
a fr*%in headache. I 'spose the argument would be as to what
constitutes 'excess'.

Turned into a good thread anyway. Thanks folks.
tim
Jul 23 '05 #9
VK
> Javascript is a bit like tequila methinks.

I would say fugurally that you're drinking "Bloody Mary" of your own
mix. ;-)
var res = countyText.replaceChild(top["d*isplay"].document.createTextNo*de(chosenCounty),countyText .fi*rstChild);

! ? ! ? ! ?
- It hurts, man! How can you drink it?!

Let's switch at least on tequila methinks:

<!-- in your left frame -->
var frameTag =
top.frames[1].document.getElementById("prop_county_display");
frameTag.innerHTML = "It works!";

<!-- in your right frame -->
<span id="prop_county_display" style="color: darkred">&nbsp</span>
<!-- actually it would be nice to use 'class' for styling; on the next
glass maybe -->

(1) Try never use string names within frames[]. It's senseless (Give me
the property "Display" from frames[] array! Eh?). Most browsers learned
to translate it semi-properly, but not all of them and not always
(Firefox in the particular doesn't like it).
(2) Don't bother with nodes. If you decided to use conventional HTML,
moreover with frames, nodes are ... strange here. Easier you do -
better it will work.

Jul 23 '05 #10
VK
or if you need to create all new element from the scrach:

<!-- in your left frame -->
var out = top.frames[1].document.body*;
// or some pre-existing element
// within the body

var countryTag = document.createElement('SPAN');
countryTag.innerHTML = "FooBar";
countryTag.style.color = 'darkred';
out.insertBefore(countryTag,null);

Jul 23 '05 #11
VK wrote:
Javascript is a bit like tequila methinks.
<!-- in your left frame -->
var frameTag =
top.frames[1].document.getElementById("prop_county_display");
frameTag.innerHTML = "It works!";

<!-- in your right frame -->
<span id="prop_county_display" style="color: darkred">&nbsp</span>
<!-- actually it would be nice to use 'class' for styling; on the next
glass maybe -->

Hi VK:
Thanks for the good example. Yes it works, but only for second.
IOWS: The text is briefly rendered then it disappears. Weird!

//Here is my working code as I have it:
var frameTag = top.document.getElementById("display");
var optionValue =
parseInt(listObject.options[listObject.selectedIndex].value);
frameTag["src"] = "short-forms/" + adForms[optionValue];

// your code as modified for var name and inserted text
var placeHolder =
top.frames[1].document.getElementById("prop_county_display");
placeHolder.innerHTML = "HELLO FROM THE DOCUMENT";

// no function is called following this one, and no javascript
// error message appears in the console. I suspect that something
// is wrong with my code.

Thanks
tim
Jul 23 '05 #12
VK
OK... I guess you've lost me here. So what *exactly* your current task
is?

(1) Update an HTML element on the page currently displayed in the
"Display" frame.
(2) Load a new page into "Display" frame;
(3) Load a new page into "Display" frame and right away update an HTML
element on the newly displayed page.

Whatever you really need, your current code does neither of above :-(

Could you mark the proper variant (1-2-3) so I wouldn't answer on all
three of them.

Jul 23 '05 #13
VK wrote:
OK... I guess you've lost me here. So what *exactly* your current task
is?

(1) Update an HTML element on the page currently displayed in the
"Display" frame.
(2) Load a new page into "Display" frame;
(3) Load a new page into "Display" frame and right away update an HTML
element on the newly displayed page.

Whatever you really need, your current code does neither of above :-(
<sigh>Guess I ate the worm ....
Could you mark the proper variant (1-2-3) so I wouldn't answer on all
three of them.


3 : load and update
=

thnx
tj

Jul 23 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

385 posts views Thread by Xah Lee | last post: by
14 posts views Thread by Roger Withnell | last post: by
14 posts views Thread by BrendanMcPherson | last post: by
42 posts views Thread by smerf | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.