开发者

offset correct calculation for IE?

In my javascript method I have this:

if (getInternetExplorerVersion() != '-1') {
        alert("IE!");
        Ice.Menu.showIt(targCompObject.offsetLeft
                + targCompObject.parentNode.offsetLeft,
                targCompObject.offsetTop
                        + targCompObject.parentNode.offsetTop, popupMenu,
                targComp);
    } else {
        Ice.Menu.showIt(targCompObject.offsetLeft,
                targCompObject.offsetTop, popupMenu, targComp);
    }

On FF and Chrome the else part is working fine. On IE, I had to change to calculation so now I have the main if... which is still not good.

Do you know any alternative?

UPDATE: Forgot to mention that for IE, the left is correctly calculated but for top it's not.

Temporary work-around (ugly of course) is that I have decreased x number of pixels from teh calculation to fit the position where I want the function to display the pop开发者_开发技巧up on IE.

Thanks.


Cant you use conditional stylesheets and change the styles of whatever is not displaying correctly?

<!--[if IE]>
        <link rel="stylesheet" type="text/css" href="iefix.css" />
<![endif]-->


You should never do "browser detection" like this. It's a big "no no" in web development, because it leads to many follow-up problems.

Instead, first make sure that your page isn't running in "quirks mode", by checking that your HTML starts with a correct DOCTYPE and then validate your page and remove all errors: http://validator.w3.org/

If your page then still needs special treatment for IE look up "feature detection" and try to use that to do something else.

(However in your case feature detection may not be the solution. For a more concrete help about this specific problem, we'll need me details: an explanation what "Ice" is, HTML code and/or a running example).


There was a div with a margin-top and that was the cause of incorrect left offset calculation for IE.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜