Forum Moderators: open
This script however still executes (clicking every four times will lead Firefox to declare it can not find "parent.border" which is the frame called border. I'm trying to keep it from executing that bit in the first place when there are no frames (to keep from having any JavaScript errors).
Here is the code, what am I doing wrong here?
//<![CDATA[
if (top.location!=self.location)
{
var clickCount = 0;
var clickSpacing = 4;
var clickCycle = 22;
document.onclick = function()
{
clickCount = ++clickCount % clickCycle // if 22, return to zero
if(clickCount &&!(clickCount % clickSpacing)) // if clickCount is non-zero multiple of clickSpacing
parent.border.location
= 'http://example.com/border'
+ (clickCount/clickSpacing)
+ '.php';
}
}
else if (top.location==self.location)
{
return false;
}
////]]>
if (parent.border)
if (parent.border!= 'undefined')
if (parent.border!= 1)
None of these seem to work as the script keeps executing if the frame does not exist. I am of course testing this script on a page that is not currently in a frameset and so there is no frame called "border". The same should (not) happen if I was testing in frames but none of the frames had a name of "border".
So I'm still stuck on this challenge.
John
<script type="text/javascript">
//<![CDATA[
if (parent.border)
{
var clickCount = 0;
var clickSpacing = 4;
var clickCycle = 22;
document.onclick = function()
{
clickCount = ++clickCount % clickCycle // if 22, return to zero
if(clickCount &&!(clickCount % clickSpacing)) // if clickCount is non-zero multiple of clickSpacing
parent.border.location
= 'http://example.com/border'
+ (clickCount/clickSpacing)
+ '.php';
}
}
else
if (parent.border!= 'undefined')
{
alert('undefined');
}
////]]>
</script>
To add a restrictive condition to an already existing script that is located in an external file all that has to be done is to check if the object autocasts to true...is that the correct terminology btw?
Thankfully this is all I had to add around the original script...
if (parent.border)
{
}
Finally the script that works only if a frame with the name "border" exists that produces no errors while serving application/xhtml+xml and as an external file IoI...
Here is the combined script that appears in the external file now...
//<![CDATA[
if (parent.border)
{
var clickCount = 0;
var clickSpacing = 4;
var clickCycle = 22;
document.onclick = function()
{
clickCount = ++clickCount % clickCycle // if 22, return to zero
if(clickCount &&!(clickCount % clickSpacing)) // if clickCount is non-zero multiple of clickSpacing
parent.border.location
= 'http://example.com/border'
+ (clickCount/clickSpacing)
+ '.php';
}
}
////]]>
Hopefully someone else will find my wandering in the dark useful somehow! :)
John