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

I

imaband

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();
}
 
M

Martin Honnen

imaband said:
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.
 
C

CodeHopper

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
 
C

CodeHopper

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
 
M

Martin Honnen

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();
 
C

CodeHopper

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
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top