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

Discussion in 'Javascript' started by imaband, Nov 15, 2004.

  1. imaband

    imaband Guest

    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();
    }
    imaband, Nov 15, 2004
    #1
    1. Advertising

  2. 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/
    Martin Honnen, Nov 15, 2004
    #2
    1. Advertising

  3. imaband

    CodeHopper Guest

    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!
    CodeHopper, Nov 15, 2004
    #3
  4. imaband

    CodeHopper Guest

    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!
    CodeHopper, Nov 16, 2004
    #4
  5. 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/
    Martin Honnen, Nov 16, 2004
    #5
  6. imaband

    CodeHopper Guest

    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!
    CodeHopper, Nov 16, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leon
    Replies:
    1
    Views:
    10,175
    Boban Dragojlovic
    Jun 24, 2003
  2. nn
    Replies:
    10
    Views:
    1,002
  3. Replies:
    2
    Views:
    444
  4. John
    Replies:
    2
    Views:
    364
  5. Jim Cobban
    Replies:
    0
    Views:
    107
    Jim Cobban
    Jul 31, 2005
Loading...

Share This Page