我自己有一个activex控件,加载到浏览器中
当控件尺寸足够时,不需要滚动条
当浏览器窗口缩小时,需要自动显示出滚动条以便用户可以通过滚动条看到被遮盖的部分请各位大虾说说,用js该怎么写?<HTML>
<head>
<title>xxxxx</title>
</head>
<body topmargin=0 bottommargin=0 leftmargin=0 rightmargin=0 onload="document.body.scroll='yes'">
<center>
<OBJECT
classid="clsid:xxxxxxxxxxxxxxxxxxxxxx"
width=100%
height=100%
align=center
hspace=0
vspace=0>
</OBJECT>
</center>
</body></html>

解决方案 »

  1.   

    <OBJECT 外层包一个DIV, 设置DIV的最小高宽即可可以用CSS的 max-width , max-height也可以写JS控制.
      

  2.   

    你的OBJECT的width与height不要设为100%,以像素为单位试试<OBJECT
    classid="clsid:xxxxxxxxxxxxxxxxxxxxxx"
    width="200px"
    height="150px"
    align=center
    hspace=0
    vspace=0>
    </OBJECT>
      

  3.   

    <HTML>
    <head>
    <title>xxxxx</title>
    </head>
    <body topmargin=0 bottommargin=0 leftmargin=0 rightmargin=0>
    <center>
    <div id="ObiFrame" style="width:500px;height:400px;overflow:auto;">
    <OBJECT
    classid="clsid:xxxxxxxxxxxxxxxxxxxxxx"
    width=100%
    height=100%
    align=center
    hspace=0
    vspace=0>
    </OBJECT>
    </div>
    </center>
    </body></html>
    div的大小如果不是固定的话,可以通过JS来控制
      

  4.   

    设置容器的style
    overflow:auto<div style="overflow:auto;">
    </div>
      

  5.   

    谢谢各位的解答
    我试了过了,还是有点问题我这个控件会根据窗口大小自动调整,只是当窗口大小小于1024*768时才需要滚动条,其他时候控件会自动充满窗口<div id="ObiFrame" style="width:1024px;height:768px;overflow:auto;">
    当尺寸小于1024*768时滚动条是有了
    但是当尺寸大于1024*768时控件不会自动充满整个窗口,它一直保持这个大小不变了要怎么办???如果解决问题了,再开帖送分
      

  6.   

    //给body添加onresize事件
    function OnResize()
    {
        if (窗口尺寸大于1024*768)
        {
             改变div到适和大小;
        }
        else
        {
             改变div为1024*768;
        }
    }
    伪代码
      

  7.   

    <div id="ObiFrame" style="overflow:auto;">通过js设置div容器的高度,然后通过 function load()
    {
     var container =document.getElementById("ObiFrame");
    container.style.height=document.documentElement.clientHeight;
    container.style.width= document.documentElement.clientWidth ;
    }
    window.attachEvent("load",load);
    window.attachEvent("resize",load);
      

  8.   


    何谓"通过js设置div容器的高度"?<HTML>
    <head>
    <title>xxxx</title>
    </head>
    <script language="JavaScript">
    <!--function load()
    {
    var container =document.getElementById("ObiFrame");
    container.style.height=document.documentElement.clientHeight;
    container.style.width= document.documentElement.clientWidth ;
    }
    window.attachEvent("load",load);
    window.attachEvent("resize",load);//-->
    </script><body topmargin=0 bottommargin=0 leftmargin=0 rightmargin=0>
    <center>
    <div id="ObiFrame" style="width:1024px;height:768px;overflow:auto;">
    <OBJECT
    classid="clsid:xxxxxxxxxxxxxxxx"
    width=100%
    height=100%
    align=center
    hspace=0
    vspace=0>
    </OBJECT>
    </div>
    </center>
    </body></html>该怎么样写呢?
    我就是属于对JS一窍不通的那种水平
      

  9.   

    前面不是已经写了如果设置div的高度宽度了吗? 
      

  10.   


    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js" ></script><div id="obj" style="width:100%;height:100%;background-color:#d23;overflow:auto;"></div>
    <script>
    function myresize()
    {
    var h=document.body.clientHeight;
    var w=document.body.clientWidth; if(h<768){
    $("#obj").height("768");
    } if(w<1024){
    $("#obj").width("1024");
    } $("#obj").html($("#obj").html()+"I")
    }
    $(function(){myresize()});
    $(window).resize(function(){myresize()});//IE在鼠标resize时就会不停的发resize事件.如果你一次移动只想发一次.可以查一下jquery的wresize事件</script>
    另外flex的中对它的swf控件如何处理的,你也可以借鉴一下
      

  11.   

    style="overflow:auto;"或者style="overflow:hidden;">隐藏
      

  12.   

    这样写有什么不对呢?<HTML>
    <head>
    <title>xxxxxxxx</title>
    </head>
    <script language="JavaScript">
    function load()
    {
    var container=document.getElementById("ObiFrame");
    var h=document.body.clientHeight;
    var w=document.body.clientWidth; if(w<1024)
    {
    w=1024;
    } if(h<768)
    {
    h=768;
    } container.style.width=w;
    container.style.height=h;
    }window.attachEvent("load",load);
    window.attachEvent("resize",load);</script><body topmargin=0 bottommargin=0 leftmargin=0 rightmargin=0>
    <center>
    <div id="ObiFrame" style="overflow:auto;">
    <OBJECT
    classid="clsid:xxxxxxxxxxxxxxxxxxxxx"
    width=100%
    height=100%
    align=center
    hspace=0
    vspace=0>
    </OBJECT>
    </div>
    </center>
    </body></html>
      

  13.   

    script放到head中 或者body里面就对了
    <HTML>
    <head>
    <title>xxxxxxxx</title>
    <script language="JavaScript">
    function load()
    {
    var container=document.getElementById("ObiFrame");
    var h=document.body.clientHeight;
    var w=document.body.clientWidth;if(w<1024)
    {
    w=1024;
    }if(h<768)
    {
    h=768;
    }container.style.width=w;
    container.style.height=h;
    }window.attachEvent("load",load);
    window.attachEvent("resize",load);</script>
    </head>
    <body topmargin=0 bottommargin=0 leftmargin=0 rightmargin=0>
    <div id="ObiFrame" style="overflow:auto;">
    <OBJECT
    classid="clsid:xxxxxxxxxxxxxxxxxxxxx"
    width=100%
    height=100%
    align=center
    hspace=0
    vspace=0>
    </OBJECT>
    </div>
    </body></html>
      

  14.   

    还是不行var container=document.getElementById("ObiFrame");
    var h=document.body.clientHeight;
    var w=document.body.clientWidth;if(w<1024)
    {
    w=1024;
    }if(h<768)
    {
    h=768;
    }container.style.width=w;
    container.style.height=h;仔细看这个代码,好象不是很对吧控件的大小它本身会自动调整的,当它在1024*768的时候它就保持这个尺寸不变了
    如果此时窗口继续缩小,就需要滚动条了
    我看这个代码似乎是在设定控件大小???
      

  15.   

    分辨率1024*768时,你实际的body高宽不适1024 和768 还有工具栏,状态栏等。。我贴出的代码是设置容器div的高宽,并让如果内容大于容器时,让容器出现滚动条。。