Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > document.write won't work just after an href link in a frame

Reply
Thread Tools

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

 
 
imaband
Guest
Posts: n/a
 
      11-15-2004
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();
}
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      11-15-2004


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/
 
Reply With Quote
 
 
 
 
CodeHopper
Guest
Posts: n/a
 
      11-15-2004

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!
 
Reply With Quote
 
CodeHopper
Guest
Posts: n/a
 
      11-16-2004
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!
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      11-16-2004


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/
 
Reply With Quote
 
CodeHopper
Guest
Posts: n/a
 
      11-16-2004
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!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
href="javascript:func()" vs href="#" onclick="javascript:func()" CRON HTML 24 06-20-2006 08:05 PM
onClick method question (this.href and document.location.href) yogesh.bhardwaj@gmail.com Javascript 2 02-03-2005 02:38 PM
difference between location.href and window.location.href? saiho.yuen Javascript 3 09-14-2004 06:51 PM
Problem: Setting MSIE iframe innerHTML change relative href/src to absolute href/src Soren Vejrum Javascript 4 07-05-2003 01:47 PM
window.opener.location.href doesn't work in frame Leon ASP .Net 1 06-24-2003 01:57 PM



Advertisments