IE的getBoundingClientRect在浏览器中给出了不同于windows.forms.webbrowser的答案 - 为什么?

时间:2008-11-26 17:00:57

标签: c# browser mshtml

采取以下html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
    <title>Basic Layout</title>
    <style type="text/css">
        html,body,div{font-family:Verdana}
        #Head{border-bottom:solid 10px #369}
        #Body{margin-left:200px;background-color:#def}
        #Body h2{float:left;margin-left:-200px;padding:10px;font-size:1em;}
        #Foot{border-top:dashed 1px #369}
        p{page-break-inside:avoid}
    </style>
    <script>
        document.onclick = function() {
            alert(document.getElementById("Body").getBoundingClientRect().left);
        }
    </script>
</head>
<body>
    <div id="Head">
        <h1>Basic Layout Header</h1>
    </div>
    <div id="Body">
        <h2>Body Header</h2>
        <p>
            Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Mauris pretium. Morbi
            nisi velit, lacinia vitae, porttitor nec, laoreet nec, neque. Fusce id dolor. Vivamus
            scelerisque libero. Fusce aliquet gravida dui. Integer vulputate bibendum pede.
            Donec fringilla porta sem. Donec justo pede, fermentum eu, mattis a, malesuada id,
            erat. Maecenas hendrerit justo vitae felis. Praesent ut purus. Pellentesque turpis
            tortor, lobortis sed, fringilla venenatis, mattis nec, ipsum. Nunc non diam. Maecenas
            gravida mollis quam. Aenean nec urna. Quisque gravida, nulla a vulputate mattis,
            mauris justo mollis leo, et pellentesque eros augue sit amet urna. Aliquam rhoncus
            erat in mauris. Nullam ut urna. Nam pharetra, purus ac ultricies consectetuer, est
            leo aliquam augue, vitae pulvinar dui mi scelerisque mi. Integer urna. Praesent
            risus libero, porttitor vel, auctor gravida, posuere vel, felis.
        </p>
    </div>
    <div id="Foot">
        <p>Footer</p>
    </div>
</body>
</html>

将其加载到浏览器中,然后点击任意位置 - 即可获得210 这是#Body div的左值

但是在带有webbrowser控件的win表单上,导航到相同的html

    webBrowser1.Navigate(_Url);

再次点击,即可获得10。

为什么......为什么......为什么?

2 个答案:

答案 0 :(得分:0)

更新

将此添加到head元素中,(我已经安装了ie8 beta 2)

<META http-equiv="X-UA-Compatible" content="IE=8">

并且它有效(显示208),但

<META http-equiv="X-UA-Compatible" content="IE=7">

仍显示10,这需要适用于ie 7

答案 1 :(得分:0)