简体   繁体   English

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

[英]IE's getBoundingClientRect gives different answer in browser than in windows.forms.webbrowser - why?

Take the following html 采取以下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>

Load it into your browser and click anywhere - you get 210 this is the left value for the #Body div 将其加载到浏览器中,然后单击任意位置-您将获得210,这是#Body div的左侧值

However on a win form with a webbrowser control on it, navigate to the same html 但是,在带有Webbrowser控件的Win窗体上,导航到相同的html

    webBrowser1.Navigate(_Url);

Click again, and you get 10. 再次单击,您将获得10。

Why... why... why? 为什么...为什么...为什么?

Update: 更新:

added this to the head element, (I have ie8 beta 2 installed) 将此添加到head元素,(我安装了ie8 beta 2)

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

and it works (208 is shown), but 它可以工作(显示了208),但是

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

still shows 10, this needs to work for ie 7 仍然显示10,这需要为7工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM