Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    clearing dynamic iframe content

    I have an iframe. When I click on a link I want to pass image url and text information to a javascript function and build an html file to put in this iframe with said information. I can get stuff into the iframe but I don't seem to be able to clear previous content out. Content just concatenates.

    All the info I've found in my web searches suggests that I use the document.clear() method. But this doesn't seem to work. One of the pages I found said the clear method was deprecated. I've also tried just replacing the entire iframe with a blank.html and then writing my code into it all over again but this doesn't work properly either. It requires a double click. One to clear things out and one to put new content into. Which makes no sense whatsoever.

    ################
    Javascript Code So Far:
    ################

    function imageDisp(thisImage, thisText) {

    window.frames['testIframe'].window.document.clear;
    window.frames['testIframe'].location = "blank.html";

    window.frames['testIframe'].window.document.open;
    window.frames['testIframe'].window.document.write('<html><head><title>Image</title></head>');
    window.frames['testIframe'].window.document.write('<body bgcolor="#FFCC66" onLoad="window.focus()"><center><img src=');
    window.frames['testIframe'].window.document.write(thisImage);
    window.frames['testIframe'].window.document.write('><p><font size=1>');
    window.frames['testIframe'].window.document.write(thisText);
    window.frames['testIframe'].window.document.write('<p></font></center>');
    window.frames['testIframe'].window.document.write('</body></html>');
    window.frames['testIframe'].window.document.close;

    }//end function

    ################
    HTML Code So Far:
    ################

    <a href="javascript:imageDisp('http://www.arcsecond.net/thumbs/jeepWThum.jpg', 'Jeep Text')">Test 1</a><br>
    <a href="javascript:imageDisp('http://www.arcsecond.net/thumbs/faceSubThum.jpg', 'Sub Text')">Test 2</a><br>
    <a href="blank.html" target="testIframe">Clear Frame</a><br>

    <p>
    <iframe id="testIframe" name="testIframe" src="blank.html"></iframe>



    Is there another method for clearing dynamic content? Thanks for any help.

    -James
    www.arcsecond.net
    james_parks@hotmail.com

  • #2
    Regular Coder
    Join Date
    Nov 2004
    Location
    The land of chocolate
    Posts
    226
    Thanks
    1
    Thanked 16 Times in 16 Posts
    You may want to use innerHTML here, instead of sticking with document.write.
    Code:
    document.testIframe.document.body.innerHTML="blah"
    where blah is any HTML you want (including an empty string in order to clear).

    I would suggest a different approach though. If you are not loading any external pages in this iframe, then I don't see why you shouldn't use a scrolling div.
    -Snow

    Susie, if you want to see your doll again, leave $100 in this envelope by the tree out front. Do NOT call the police. You CANNOT trace us. You CANNOT find us.

    Sincerely,
    - Calvin.

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    This works ok for IE. I put the html in a variable to clean it up a bit.
    Code:
    <script type="text/javascript">
    function imageDisp(thisImage, thisText){
    myHTML='<html><head><title>Image</title></head>\n'+
           '<body bgcolor="#FFCC66" onLoad="window.focus()">'+
           '<center><img src="'+thisImage+'">\n'+
           '<p><font size=1>'+thisText+'<p></font></center>\n</body></html>';
    parent.document.frames[0].document.open();
    parent.document.frames[0].document.write(myHTML);
    parent.document.frames[0].document.close();
    }//end function
    </script>
    
    <a href="javascript:imageDisp('http://www.arcsecond.net/thumbs/jeepWThum.jpg', 'Jeep Text')">Test 1</a><br>
    <a href="javascript:imageDisp('http://www.arcsecond.net/thumbs/faceSubThum.jpg', 'Sub Text')">Test 2</a><br>
    <a href="blank.html" target="testIframe">Clear Frame</a><br>
    
    <p>
    <iframe id="testIframe" name="testIframe" src="blank.html"></iframe>

    /Bob


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •