談談Iframe的自動重新整理

來源:互聯網
上載者:User

  最近遇到需要頁面自動重新整理的功能,於是乎就想到了Iframe……

  Iframe在單個頁面中可以正常的實現自動重新整理

  舉一個關於不斷往a.txt中寫資訊的小例子:

 

all.cgi頁面的代碼

<html>
<head>
 <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>
 <title>all device</title>
</head>
<body>
   <iframe id='myIfm'  src='fifo.cgi' width='150' height='150'></iframe>
</body></html>

  int fifo;
  if ((fifo = open("a.txt", O_WRONLY | O_APPEND)) < 0)                   //判斷開啟a.txt檔案是否成功

   {
         printf("open   error:   %s/n",   strerror(errno));                     //錯誤列印錯誤資訊,返回
         return(0);
    }
    write(fifo,"bbb/n",4);                                                    //正確的時候就不斷的往a.txt檔案中寫“bbb”
   運行一下,成功……

 

 

   但是在需要用button提交的時候只能執行一次,這個問題迷糊了我3天,終於把它弄明白了,分享一下,希望可以幫到和我一樣遭遇的朋友……

   舉一個關於用按鈕提交使頁面不斷往a.txt中發送資訊的小例子:

  

   <script javascript="javascript">

   function ok()

  {
     var myIfm=document.all("myIfm").src="fifo.cgi"; //這個調用的src可以是html,cgi,c……任何形式的,根據自己的需求而定
     window.setTimeout( "ok2()",1000);       //需要用到這句(一定要用)是因為載入另一個頁面的時候需要時間,

                                                                    //只能等到第一個頁面載入完畢後才能調用
   }
   function   ok2(){ 
    //alert("ddd");
     document.all( "myIfm").contentWindow.location="fifo.cgi";
  }

   </script>

 

all.cgi頁面的代碼

<html>
<head>
 <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>
 <title>all device</title>
</head>
<body>
  <input  type='submit'  name='btnOpen'  value='Open'  onclick="javascript:ok()"/>
  <iframe id='myIfm'  src='' width='150' height='150'></iframe>
</body></html>

 

fifo.cgi頁面的代碼

 int fifo;
  if ((fifo = open("a.txt", O_WRONLY | O_APPEND)) < 0)                   //判斷開啟a.txt檔案是否成功

   {
         printf("open   error:   %s/n",   strerror(errno));                     //錯誤列印錯誤資訊,返回
         return(0);
    }
    write(fifo,"bbb/n",4);                                                    //正確的時候就不斷的往a.txt檔案中寫“bbb”
   運行一下,成功……

 

 

   到此,大功告成嘍,沒白忙活一陣子,終於弄出來了,很是興奮啊……

   希望對某些和我遇到過一樣的問題的朋友有所協助……

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.