Dynamic IFrame Creation Caching Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • polymorphic
    New Member
    • Oct 2006
    • 28

    Dynamic IFrame Creation Caching Problem

    I have succeeded in embedding PDF files in a dynamic iframe. The problem is that I need the PDF to cache. If the PDF remains the same from page load to page load then the pdf is somehow cached with the html page. But if I try to navigate to another pdf in the IFRAME then no caching occurs. Is the problem in the IFRAME reloading instead of just refreshing the pdf?

    [CODE=javascript]<SCRIPT type="text/javascript">

    var pageNo;
    var nav;
    var iframe;
    var embed;
    pageNo = 1;

    var embed = "<EMBED src=/Catalog/Page" + pageNo + ".pdf scrollbar=1&amp ;messages=0&amp ;statusbar=0&am p;navpanes=0 width=600 height=650></EMBED>";

    function makeIframe() {
    iframe = document.create Element("IFRAME ");
    iframe.src = "javascript:'<H TML><HEAD>";
    iframe.src += "<TITLE>Dyn amic IFrame</TITLE>";
    iframe.src += '</HEAD><BODY>';
    iframe.src += '<FORM method=get action=dummy.ph p>';
    iframe.src += "</FORM>" + embed + "</BODY></HTML>'";
    document.body.a ppendChild(ifra me);
    f = document.getEle mentById('IFRAM E');
    }

    function navigate(nav){

    if (nav == "f")
    {
    pageNo = pageNo + 1;
    embed = "<EMBED src=/Catalog/Page" + pageNo + ".pdf scrollbar=1&amp ;messages=0&amp ;statusbar=0&am p;navpanes=0 width=600 height=650></EMBED>"
    }
    else if (nav == "b")
    {
    pageNo = pageNo - 1;
    embed = "<EMBED src=/Catalog/Page" + pageNo + ".pdf scrollbar=1&amp ;messages=0&amp ;statusbar=0&am p;navpanes=0 width=600 height=650></EMBED>"
    }
    else if (nav == "i")
    {
    pageNo = 2;
    embed = "<EMBED src=/Catalog/Page" + pageNo + ".pdf scrollbar=1&amp ;messages=0&amp ;statusbar=0&am p;navpanes=0 width=600 height=650></EMBED>"
    }

    this.document.f rames['IFRAME'].location.reloa d(true);

    }[/CODE]
  • polymorphic
    New Member
    • Oct 2006
    • 28

    #2
    Dynamic IFrame Creation Caching Problem

    I've been working on this problem on and off for a while now. I need to dynamically embed a pdf into an iframe. It works fine but the pdf is not caching. I assume that this is because the iframe is dynamic so that each time a new pdf is opened, a new iframe is created? Is there a way around this? I moved this from asp to html so that it supposedly WOULD cache the pdf. Could it be because I call the create iframe function from the onLoad event (onLoad="makeIf rame()")? Here is the function I am using:

    [CODE=javascript]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD><TI TLE>2007 Catalog</TITLE>
    <META http-equiv=Content-Type
    content="text/html; charset=windows-1252">
    <SCRIPT type="text/javascript">

    var pageNo;
    var nav;
    pageNo = 1;

    iframe = document.create Element("IFRAME ");

    function makeIframe(nav) {

    if (nav == "f")
    {
    if (pageNo < 102)
    {
    pageNo = pageNo + 1;
    }
    }
    else if (nav == "b")
    {
    if (pageNo != 1)
    {
    pageNo = pageNo - 1;
    }
    }
    else if (nav == "i")
    {
    pageNo = 2;
    }

    iframe.src = "javascript:'<H TML><HEAD>";
    iframe.src += "<TITLE>Dyn amic IFrame</TITLE>";
    iframe.src += '</HEAD><BODY>';
    iframe.src += '<FORM method=get action=dummy.ph p>';
    iframe.src += "</FORM><EMBED src=/Catalog/Page_" + pageNo + ".pdf toolbar=0;scrol lbar=1&amp;page mode=none&amp;z oom=50&amp;mess ages=0&amp;stat usbar=0&amp;nav panes=0 width=600 height=650></EMBED></BODY></HTML>'";
    document.body.a ppendChild(ifra me);
    }
    </SCRIPT>
    <link href="../css/style.css" rel="stylesheet " type="text/css">
    <link rel="stylesheet " href="styleshee ts/main.css" type="text/css">
    </HEAD><BODY style="margin:0 %" onLoad="makeIfr ame()">
    <table>
    <tr>
    <td width = "50%"><font color="#0000A0" >
    <b>2007 Catalog</b></font>
    </td>
    <td width = "13%"></td>
    <td width = "50%" align = "right">
    <input type = "button" name = "bPrevious" value = "Previous" onClick="makeIf rame('b')">
    <input type = "button" name = "bNext" value = "Next" onClick="makeIf rame('f')">
    <input type = "button" name = "bIndex" value = "Index" onClick = "makeIframe('i' )">
    <input type = "button" name = "bClose" value = "Close" onClick = "this.close ">
    </td>
    </tr>
    </table>
    </BODY>
    </HTML>[/CODE]

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, polymorphic.

      I can't be positive, but perhaps it has something to do with the fact that you are using embed tags.

      What would happen if you just set the src of the iframe to the URI of the PDF?

      Comment

      • polymorphic
        New Member
        • Oct 2006
        • 28

        #4
        Originally posted by pbmods
        Heya, polymorphic.

        I can't be positive, but perhaps it has something to do with the fact that you are using embed tags.

        What would happen if you just set the src of the iframe to the URI of the PDF?
        Um, you could be right. The pdfs cache when I open the html independently of the rest of the site. However, if I link to the html page then no caching. What is the difference?

        Here is the changed script:
        Code:
        <SCRIPT type="text/javascript">
        
        var pageNo;
        var nav;
        pageNo = 1;
        
        function makeIframe(nav) {
        
        if (nav == "f")
         {
        	if (pageNo < 102)
        	{
            pageNo = pageNo + 1;
            }
         }
         else if (nav == "b")
         {
        	if (pageNo != 1)
        	{
            pageNo = pageNo - 1;
            }
         }
         else if (nav == "i")
         {
         	pageNo = 2;
         }
        var iframe = document.createElement("IFRAME");
        iframe.setAttribute("src", "/Catalog/Page_" + pageNo + ".pdf");
        iframe.setAttribute("id", "contentFrom");
        document.body.appendChild(iframe);
        }
        </SCRIPT>
        The href link is in an includes file (which is called from an asp file) as follows:

        Code:
        <!-- #include virtual="/includes/leftMenu.inc" -->
        Code:
        <tr>
         <td><a href="catalog.html" target = "_blank" onMouseOut="MM_swapImgRestore();" onMouseOver="MM_swapImage('default_r3_c2','','images/default_r3_c2_f2.gif',1);"><img name="default_r3_c2" src="images/default_r3_c2.gif" width="160" height="40" border="0" alt=""></a></td>
        </tr>
        I do not understand why it makes a difference.

        Comment

        Working...