Reputation: 1590
Working through a javascript book that wants me to make a simple factorial calculator and I keep getting the error "This page is not loaded within the correct frameset" when I click the calculate button in the code below. Now the code is programmed to throw back this error if it's not in the correct frameset, but my question is why isn't it?
Edit: To clarify, I'm definitely starting off on calcfactorialtopframe.htm
.
calcfactorialtopframe.htm
<html>
<head>
<title>Example</title>
<script type="text/javascript">
function calcFactorial(factorialNumber)
{
var factorialResult = 1;
for (; factorialNumber > 0; factorialNumber--)
{
factorialResult = factorialResult * factorialNumber;
}
return factorialResult;
}
</script>
</head>
<frameset cols="100%,*">
<frame name="fraCalcFactorial" src="calcfactorial.htm" />
</frameset>
</html>
calcfactorial.htm
<html>
<head>
<title>Example</title>
<script type="text/javascript">
function butCalculate_onclick()
{
try
{
if (window.top.calcFactorial == null)
throw "This page is not loaded within the correct frameset";
if (document.form1.txtNum1.value == "")
throw "!Please enter a value before you calculate its factorial";
if (isNaN(document.form1.txtNum1.value))
throw "!Please enter a valid number";
if (document.form1.txtNum1.value < 0)
throw "!Please enter a positive number";
document.form1.txtResult.value =
window.parent.calcFactorial(document.form1.txtNum1.value);
}
catch(exception)
{
if (typeof(exception) == "string")
{
if (exception.charAt(0) == "!")
{
alert(exception.substr(1));
document.form1.txtNum1.focus();
document.form1.txtNum1.select();
}
else
{
alert(exception);
}
}
else
{
alert("The following error occursed " + exception.message);
}
}
}
</script>
</head>
<body>
<form action="" name="form1">
<input type="text" name="txtNum1" size="3" /> factorial is
<input type="text" name="txtResult" size="25" /><br />
<input type="button" value="Calculate Factorial" name="butCalculate" onclick="butCalculate_onclick()" />
</form>
</body>
</html>
Upvotes: 1
Views: 284
Reputation: 69
Yes this is Chrome bug, working Fine in Latest versions of Firefox, IE and Opera :)
Upvotes: 2
Reputation: 1590
This is a Chrome specific bug.
I did previously try the same code in IE with the same error, although upon a trying it again it appears to be working in IE but still not working in Chrome.
Upvotes: 0
Reputation: 207537
My guess is you are loaded calcfactorial.htm
into the address bar and not calcfactorialtopframe.htm
.
Upvotes: 0