PDA

View Full Version : frames on safari 3 does not work



joecool2005
01-16-2008, 01:24 PM
Hi,

I have a frame that works on IE 7 but does not work on safari 3.
It shows the message like this:

TypeError: Value undefined (result of expression top.frames["toolbar"].doSomething2) is not object.

Here is the code

default.htm


<HTML>
<frameset id="frameset1" rows="119,*" name="frameset1" border="0" frameSpacing="0" frameBorder="no">
<frame name="toolbar" id="toolbar" src="button.htm" marginheight="0" marginwidth="0" scrolling="no" NORESIZE>
<frame name="top_main" id="top_main" src="button2.htm" marginheight="0" marginwidth="0" NORESIZE>
</frameset>
</HTML>


button.htm


<html>

<head>
<script>
function doSomething2(){
document.write("this is my document");
}
</script>
</head>
<body>
my page
</body>

</html>


button2.htm

<HTML>
<script>
try{

top.frames["toolbar"].doSomething2()
}
catch(e){alert(e);}
</script>
<body>
button2<br />
</body>
</HTML>

jscheuer1
01-17-2008, 07:49 AM
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:


<!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>


<!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>


<!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>