Document write to Iframe problem

Posted on 2007-10-02
Last Modified: 2008-01-09
I am seeing a particular problem in a script I have.  The script will write to an iframe 3 different values, one at a time, a click of an arrow will write the next item or back up an item.  For some reason the browser does not show #2. .

Here is a skimmed down version of the script:

        var theHI = 0;

        function forwardOne(){
              theHI = theHI + 1;
              window.frames.iHot.location = 'about:blank';
        function backOne(){
              theHI = theHI - 1;
              window.frames.iHot.location = 'about:blank';

        function showHotItem(HI) {
                    var i = frames["iHot"];
                  if(HI == 1){i.document.write('ITEM 1')};
                  if(HI == 2){i.document.write('ITEM 2')};
                  if(HI == 3){i.document.write('ITEM 3')};


<iframe name="iHot" id="iHot" src=""></iframe>
<img src=right-arrow.gif onClick=forwardOne();>
<img src=left-arrow.gif onClick=backOne();>

Do you see what could be wrong? Or could I approach this in a different way?

Many thanks,

Question by:fidoly
    LVL 63

    Accepted Solution

    Add document.close();

    Like this:

            function showHotItem(HI) {
                      var i = frames["iHot"];
                      if(HI == 1){i.document.write('ITEM 1')};
                      if(HI == 2){i.document.write('ITEM 2')};
                      if(HI == 3){i.document.write('ITEM 3')};


    Author Comment

    Worked quite well!  Thanks a MEG!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    Title # Comments Views Activity
    SharePoint JSOM error 7 32
    PHP Radio Array 4 27
    Issues with signature 19 17
    JavaScript communication inside a IFRAME 9 19
    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    In Part 1 ( we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now