Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem using javascript to write to a different frame

Status
Not open for further replies.

skills

Programmer
Jun 24, 2003
60
US
I have 2 frames. In one frame I have a form. In another, I have results show up. I can get items to appear when writing to the different frame. My problem is that all the code on the results page that was there before writing to it is no longer there, such as the background. I also have a problem with this because I have CSS coding on the initial results page, and it doesn't work once I write to it.

Any suggestions would be great.

Skills

 
i suspect you're using document.write() - this would replace anything that was there previously.

if you want to append to the current content, you'll need to append to the innerHTML of the content element, e.g.

<div id=&quot;content&quot;>
blah blah blah
</div>

<script type=&quot;text/javascript&quot;>
var el = parent.frameName.document.getElementById(&quot;content&quot;);
el.innerHTML += &quot;<br/>more content&quot;;
</script>

replace &quot;frameName&quot; with the name of your results frame


=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
<pre>IM assuming you have something like this


<html><body>
<font size=&quot;-5&quot;><small><center>Type your HTML below and then click Display Results.</center></font></b></small>
<form name=&quot;write&quot;>
<center><textarea cols=&quot;43&quot; rows=&quot;7&quot; name=&quot;display&quot;></textarea></center>
</form>
<script language=&quot;javascript&quot;>
<!--


function writeContent() {
parent.display.document.open(); parent.display.document.write(&quot;&quot;+document.write.display.value+&quot;&quot;);
parent.display.document.close();
}
//-->
</script>
<center><input type=&quot;button&quot; onClick=&quot;writeContent()&quot; value=&quot;Display Results&quot;></center>
</body>
</html>

so when you click the button itll send the information you typed in the textarea field in the code above to the display frame. But what happens is it rewrites the display page each time so what you have to do is is make it so each time it writes to the display page it adds whatever you want to it itll look something like this

<script language=&quot;javascript&quot;>
<!--


function writeContent() {
parent.display.document.open();
parent.display.document.write(&quot;&quot;+<ur tags in here>+&quot;&quot;); <!-- how you want the page to be diplayed -->
parent.display.document.write(&quot;&quot;+<user input here>+&quot;&quot;); <!-- the users input -->
parent.display.document.write(&quot;&quot;+<end ur tags>+&quot;&quot;); <!-- end everything that you put in -->
parent.display.document.close();
}
//-->
</script>




so you can jus copy this code an enter whatever tags you want...


<script language=&quot;javascript&quot;>
<!--


function writeContent() {
parent.display.document.open();
parent.display.document.write(&quot;&quot;++&quot;&quot;); parent.display.document.write(&quot;&quot;++&quot;&quot;);
parent.display.document.write(&quot;&quot;++&quot;&quot;);
parent.display.document.close();
}
//-->
</script>






If i get what your sayin this should work... I now it may sound a little hard to understand but if you need anyfurther help feel free to email me... an also email me to tell me if it works... I will also create the whole script for you for free if you would like or cant figure it out...
p.s. Ingorne the <pre> tag thats jus to insure that the HTML stays
Matt Powell
Jammer1221@aol.com
</pre>
 
Ok, I will make this very simple. Here is the two sets of code I have:



<html>
<style>
<!--
a{text-decoration:none}
a:hover{color:red}
-->
</style>
<BODY bgproperties=&quot;fixed&quot; BACKGROUND=&quot;...&quot;>
</body>
</html>


and


results.document.writeln(blanklink);



The code in red is the results page. The code in green is the code used to write to the results page. When the code in green executes, everything in red disappears.

I hope this helps.

Skills

 
Have you tried:

results.document.body.innerText = blanklink;

It worked for me in a small test.

--Dave
 
Dave, that didn't work for me. Any more suggestions?

Jonathan
 
Well, if you only just then open the window, you can try:

Code:
results.document.write(&quot;<html>&quot;);
results.document.write(&quot;<style>&quot;);
results.document.write(&quot;<!--&quot;);
results.document.write(&quot;a{text-decoration:none}&quot;);
results.document.write(&quot;a:hover{color:red}&quot;);
results.document.write(&quot;-->&quot;);
results.document.write(&quot;</style>&quot;);
results.document.write(&quot;<BODY bgproperties='fixed' BACKGROUND='...'>&quot;);
results.document.write(blanklink);
results.document.write(&quot;</body>&quot;);
results.document.write(&quot;</html>&quot;);

What browser are you using?

I would also try:

Code:
results.document.body.innerHTML = blanklink;

and

changing the child window to:

Code:
<html>
<style>
<!--
a{text-decoration:none}
a:hover{color:red}
-->
</style>
<BODY bgproperties=&quot;fixed&quot; BACKGROUND=&quot;...&quot;>
<DIV id=textPlace>
</DIV>
</body>
</html>

and trying:

Code:
results.document.all[&quot;textPlace&quot;].innerText = blanklink;

(something along the lines of what jemminger was saying, above)

Does any of this help?

--Dave
 
skills,

change your results page to this:

<html>
<style>
<!--
a{text-decoration:none}
a:hover{color:red}
-->
</style>
<BODY bgproperties=&quot;fixed&quot; BACKGROUND=&quot;...&quot;>
<div id=&quot;result_div&quot;></div>
</body>
</html>


and change your results code to this:

results.document.getElementById(&quot;result_div&quot;).innerHTML = blanklink;



=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Jeff,

That is very close, except for the fact that every time I use

results.document.getElementById(&quot;result_div&quot;).innerHTML = blanklink;

what text was shown previously is overwritten. How do I solve this problem?

Jonathan
 
Jeff,

Could you also answer my problem in thread216-598984. You were part of it, and then I lost you. I am really close on it, but I am having a problem with random <a name> throwing following links off by one or two. Any help would be great.

Jonathan
 
Try:

Code:
var oldHTML = results.document.getElementById(&quot;result_div&quot;).innerHTML;

results.document.getElementById(&quot;result_div&quot;).innerHTML = oldHTML + blanklink;

--Dave

 
uh, why not just use the concatenation operator? whole lot simpler:

results.document.getElementById(&quot;result_div&quot;).innerHTML += blanklink;



=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Indeed. Multiple threads streaming around my mind. I think I was just thinking about something else at the time. Of course, use +=.

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top