This is a comedy of errors.
document.write overwrites a page. So, the moment doSomething2() begins to be invoked, it no longer exists, unless button.htm hasn't been fully parsed yet, or the browser just wants to allow it. In FF it 'works' but the frameset never completely loads. Opera doesn't like it at all, just like Safari. Only IE seems to be completely OK with it. On top of that, the markup is invalid, and Safari appears to not want to refer to a function in the frame from the frame's name or id, rather by its number:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<title>Conforming HTML 4.01 Transitional Template</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<frameset id="frameset1" rows="119,*">
<frame name="toolbar" id="toolbar" src="button.htm" scrolling="no" frameborder="0" noresize>
<frame name="top_main" id="top_main" src="button2.htm" frameborder="0" noresize>
<noframes>
<body>
<!-- place alternative information for accessibility purposes here -->
</body>
</noframes>
</frameset>
</html>
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
body {
margin:0;
padding:0;
}
</style>
</head>
<body>
<div id="txt">my page</div>
<script type="text/javascript">
function doSomething2(){
var t=document.getElementById('txt');
t.replaceChild(document.createTextNode('this is my document'), t.firstChild);
};
</script>
</body>
</html>
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
body {
margin:0;
padding:0;
}
</style>
<script type="text/javascript">
try{
top.frames['toolbar'].doSomething2();
}catch(e){
try{
for ( var i = top.frames.length-1; i > -1; --i)
if(top.frames[i].name=='toolbar')
break;
top.frames[i].doSomething2();
}catch(e){alert(e);};
};
</script>
</head>
<body>
button2<br>
</body>
</html>
Bookmarks