On Internet Explorer my code works perfectly well, but I am using Safari on a Mac and it gives me that error. This is my code:
<!DOCTYPE html>
<html>
<head>
<title>The Me Project</title>
<link href="me.css" rel="stylesheet" type="text/css" href="me.css" />
<script type="text/javascript">
function page(setter)
{
if (setter=="home")
{
window.frames["content"].document.location.href = "home.html";
}
else if (setter=="birth")
{
window.frames["content"].document.location.href = "birth.html";
}
else if (setter=="cool")
{
window.frames["content"].document.location.href = "cool.html";
}
else if (setter=="family")
{
window.frames["content"].document.location.href = "family.html";
}
else
{
window.frames["content"].document.location.href = "home.html";
}
}
</script>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
</head>
<body>
<div id="header">
<div id="nav">
<h1>Parth's Me Project</h1>
<ul>
<li><a onclick="page('home')">Home</a></li>
<li><a onclick="page('birth')">Birth Year</a></li>
<li><a onclick="page('cool')">Cool Things</a></li>
<li><a onclick="page('family')">My Family</a></li>
</ul>
</div>
</div>
<div id="main">
<iframe src="home.html" name="content" id="content" seamless height="1000" frameborder="0"/>
</div>
<frame>
</body>
</html>
If you need the other pages, just tell me.I am trying to keep the same header and nav bar, so I am using an iframe in the bottom section.
That error is telling you that
window.frames["content"].documentresolves toundefinedso the browser can’t access thelocationproperty.Accessing the document in an iFrame is different in different browsers, see below. Also, chaining references like that is not a good idea (as you’ve discovered) as it makes debugging harder.
Note that you may still have issues if the HREF isn’t from the same domain or sub–domain. Some sites don’t let their pages be displayed in iFrames so some browsers will refuse to display them while others will open them in new tabs or windows.