Showing posts with label id. Show all posts
Showing posts with label id. Show all posts

Tuesday, March 04, 2008

IE bug: id and name in getElementById function


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Test id and name property in IE7 </title>
</head>
<body>
<input name="t1"/> Input tag with name t1, IE7 will alert "INPUT"<br />
<a name="t1">Anchor t1, if remove input element, IE7 will alert "A"</a><br />
<div id="t1">div tag with id t1</div>

<script type="text/javascript">
alert(document.getElementById('t1').tagName);
</script>
</body>
</html>

Opera has the same problem.

Wednesday, January 30, 2008

window frames property test

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<HTML>
<HEAD>
<TITLE>A frameset document</TITLE>
</HEAD>
<FRAMESET cols="40%, 60%" name="fs" id="frs">
<FRAME src="fm1.html" frameborder="0" name="fmn1" id="fmi1"/>
<FRAME src="fm2.html" frameborder="0" name="fmn2" id="fmi2"/>
</FRAMESET>
</HTML>
debug under firebug console:
>>> window
Window frames.html
>>> window.frames
Window frames.html
>>> window.frames[0]
Window fm1.html
>>> window.frames[1]
Window fm2.html
>>> window.frames[1].id
# => undefined
>>> window.frames[1].src
# => undefined
>>> window.frames[1].name
"fmn2"
>>> document.getElementById('fmi1')
<frame id="fmi1" name="fmn1" frameborder="0" src="fm1.html">
>>> document.getElementById('fmi1').id
"fmi1"

Object window has name propery, but has no id and src properties, so window.frames[1].src is undefined, we can get src value throught top window's element object, such as cument.getElementById('fmi1').id