各位。
<iframe id="mainFrame" width="100%" height="100%" onload='IFrameReSize("mainFrame");IFrameReSizeWidth("mainFrame");'  frameborder="0" scrolling="no" src="http://widget.weibo.com/list/list.php?language=zh_cn&width=1000&height=600&listid=441096097&uname=%E6%97%A0%E9%99%90%E9%9E%8D%E5%B1%B1&uid=2862199342&listname=%E9%9E%8D%E5%B1%B1%E7%94%B5%E8%A7%86%E5%8F%B0&color=&showcreate=0&isborder=1&showtitle=0&appkey=&dpc=1"></iframe>
width=1000&height=600
其中有个  宽和高。能不能用js 把这两个数用一个变量代替。因为不同的屏幕宽度不一样啊。
写成这样   width=daowidth&height=daoheight<script language=javascript>
 var daowidth;
 var daoheight;
 function IFrameReSize(iframename) {
  var pTar = document.getElementById(iframename);
  if (pTar) {  //ff
  if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight) {
  pTar.height = pTar.contentDocument.body.offsetHeight;
  daoheight=pTar.contentDocument.body.offsetHeight;
  } //ie
  else if (pTar.Document && pTar.Document.body.scrollHeight) {
  pTar.height = pTar.Document.body.scrollHeight;
  daoheight=pTar.Document.body.scrollHeight;
  }
  }
  }
  //iframe宽度自适应
  function IFrameReSizeWidth(iframename) {
  var pTar = document.getElementById(iframename);
  if (pTar) {  //ff
  if (pTar.contentDocument && pTar.contentDocument.body.offsetWidth) {
  pTar.width = pTar.contentDocument.body.offsetWidth;
  daowidth=pTar.contentDocument.body.offsetWidth;
  }  //ie
  else if (pTar.Document && pTar.Document.body.scrollWidth) {
  pTar.width = pTar.Document.body.scrollWidth;
  daowidth=pTar.Document.body.scrollWidth;
  }
  }
  }
 
 </script>
   

解决方案 »

  1.   

    var daowidth=1000;
    var daoheight=600;
    <iframe id="mainFrame" width="100%" height="100%" onload='IFrameReSize("mainFrame");IFrameReSizeWidth("mainFrame");' frameborder="0" scrolling="no" src="http://widget.weibo.com/list/list.php?language=zh_cn&width="+daowidth+"&height="+daoheight+"&listid=441096097&uname=%E6%97%A0%E9%99%90%E9%9E%8D%E5%B1%B1&uid=2862199342&listname=%E9%9E%8D%E5%B1%B1%E7%94%B5%E8%A7%86%E5%8F%B0&color=&showcreate=0&isborder=1&showtitle=0&appkey=&dpc=1"></iframe>
      

  2.   

    哥们。我的iframe 是在body中的。   那段js是在head中。那你说是不是把inframe用  <script language=javascript>
    </script>
    包起来呢?
      

  3.   

    用JS动态赋值给IFRMAE就可以了。。
      

  4.   

    没关系,js变量是全局的,在那个script节点并不会有区别
    head在body之前加载,所以在body中使用head里面js代码的全局变量是可以的当然我的确弄错了,iframe是成html,不是js字符串
    这样:
    <script>
    var daowidth=1000;
    var daoheight=600;document.getElementById("mainFrame").src="http://widget.weibo.com/list/list.php?language=zh_cn&width="+daowidth+"&height="+daoheight+"&listid=441096097&uname=%E6%97%A0%E9%99%90%E9%9E%8D%E5%B1%B1&uid=2862199342&listname=%E9%9E%8D%E5%B1%B1%E7%94%B5%E8%A7%86%E5%8F%B0&color=&showcreate=0&isborder=1&showtitle=0&appkey=&dpc=1";
    </script>
    把这段js代码放在<iframe>节点后面,那两个变量可以在这儿定义,也可以在head中的js代码中定义