472,122 Members | 1,490 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,122 software developers and data experts.

document.write won't work just after an href link in a frame

Hi,

I've got a little Quizzer program that asks a question in the upper
frame of a frameset and then lists the answer in the lower frame.
Answers can be plain text, straight html, a sound, or a LINK. I have a
function that builds the answer frame using document.write(among other
things). This code works fine until you encounter a link. It dutifully
displays the link in the lower frame but the very next question builds
the newContent perfectly but does NOT write it to the frame even
though it appears to execute it. Anybody know why?
JS

if (answerType == "link")
{
parent.frames[1].location = URL;
} else {

// pitiful attempt to clear linked page
parent.frames[1].location.href = "QuizzerAnswer.htm";

var newContent = '<html><head><title>Quizzer Answer</title>'
newContent += '</head>';
newContent += '<body>';

if (answerType == "text" || answerType == "html") {
newContent += answerValue;
}

if (answerType == "sound") {
newContent += '<embed src="' + answerValue;
newContent += '" width="170" height="25" autostart="true">'
}

newContent += '</body>';
newContent += '</html>';

parent.frames[1].document.write(newContent);
parent.frames[1].document.close();
}
Jul 23 '05 #1
5 1742


imaband wrote:
I've got a little Quizzer program that asks a question in the upper
frame of a frameset and then lists the answer in the lower frame.
Answers can be plain text, straight html, a sound, or a LINK. I have a
function that builds the answer frame using document.write(among other
things). This code works fine until you encounter a link. It dutifully
displays the link in the lower frame but the very next question builds
the newContent perfectly but does NOT write it to the frame even
though it appears to execute it. Anybody know why?


Your browser's JavaScript console might know and tell you what is wrong.
Anyway, try
parent.frames[1].document.open();
parent.frames[1].document.write(newContent);
parent.frames[1].document.close();
If that doesn't help then tell us which browser you are using, whether
you get any errors in the JavaScript console.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

Thanks Martin,

I'm using IE6 and enabled script debugging but didn't even get an error
message. I added the open() but that didn't help either. For some reason
it thinks it wrote the string but the window doesn't update. I'm
researching the location object to see if perhaps something might
"reset" the frame to whatever state is required to make this work.

Thanks for your prompt reply.

JS

Software Architect
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3
Martin,

The debugger finaly started to work and I got an "Access is Denied"
message right on the document.open() statement.

I'm using ActiveX controls to get the data I need from a CSV file. But
the page in question doesn't reference the TDC directly - only the upper
Question frame does. I'm loading CNN and Google as my LINK. Maybe they
affect the security of sibling frames somehow. I'll try and lower my
security preferences temporarily to see if it solves the problem.

JS

Software Architect
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #4


CodeHopper wrote:

The debugger finaly started to work and I got an "Access is Denied"
message right on the document.open() statement.

I'm using ActiveX controls to get the data I need from a CSV file. But
the page in question doesn't reference the TDC directly - only the upper
Question frame does. I'm loading CNN and Google as my LINK.


That is the problem, once you have loaded a page from an origin
different than the one the page with your script is loaded from you are
no longer able to access the document due to the same origin policy.
Try
parent.frames[1].location.href = 'about:blank';
parent.frames[1].document.open();
parent.frames[1].document.write(...);
parent.frames[1].document.close();

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #5
Martin (all),

Nope! Doesn't fix it. Oh well. I guess I'll just open a new window until
I can figure this one out.

I truly appreciate your help though.

Ahhhhh Technology! Isn't it WONDERFUL.

CodeHopper.

Software Architect
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Konrad Mathieu | last post: by
3 posts views Thread by Catherine Lynn Smith | last post: by
5 posts views Thread by John Taylor-Johnston | last post: by
2 posts views Thread by PhoneLover | last post: by
7 posts views Thread by Remi Bastide | last post: by
5 posts views Thread by terence.parker | last post: by
136 posts views Thread by Matt Kruse | last post: by
reply views Thread by leo001 | last post: by

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.