当找到文本范围的位置时,我似乎发现了Internet Explorer 8的问题 - 例如当前选择的文本.我还没有找到能在StackOverflow或其他地方找到任何关于此问题的报告.
TextRange.offsetLeft和TextRange.offsetTop报告范围的左上角,在IE8中我看到的所有情况都是粗略正确的,除非范围在IFrame中.当范围在IFrame内时,offsetLeft和offsetTop的值相对于其父级内的IFrame的位置移动负值.(见下面的例子)
此问题仅在以下时间出现:
在以下情况下不会出现此问题:
我的问题:
谢谢.
问题的一个例子:(参见IE8与IE9的区别)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>IE8 IFrame Text Range Position Test Page</title>
<style type="text/css">
body {
font-family: Tahoma;
}
#target {
background-color: #CCC;
position: absolute;
left: 50px;
top: 50px;
}
#bullsEye {
position: absolute;
background-color: red;
width: 5px;
height: 5px;
}
iframe {
margin: 10px 75px;
}
</style> …Run Code Online (Sandbox Code Playgroud)