Page 1 of 1

Need help stopping script from executing when not in frames!

Posted: Sun Jan 29, 2006 9:04 pm
by JAB Creations
If you test this script out it will create an error in Firefox after four clicks on the page that "parent.border" has no properties. This means I've failed to keep the script from executing when the page is not in a frame. So I just need to make the script only execute if it is inside of frames and do absolutely nothing if the page is not in frames.

Code: Select all

//<![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;
}
////]]>
John

Posted: Sun Jan 29, 2006 9:19 pm
by feyd

Code: Select all

if( typeof parent == 'object' ) {
  if( typeof parent.border != 'undefined' ) {
    parent.frames['border'].location = //
  }
}

maybe?

Posted: Sun Jan 29, 2006 9:24 pm
by JAB Creations
No, that is referencing something and in that case we now do not even check to see if that object (parent.border) exists in the first place.

I've tried setting up my script as so...

if the parent.border exists {}

Does not seem to work however as the script still attempts to execute even if the page is in no frame.

John

Script Solved!

Posted: Mon Jan 30, 2006 12:17 am
by JAB Creations
I have solved the issue...

To add detection to a script to execute only when a condition is met I used this...
if (parent.border)
{
}
I left out detecting if the object did not exist and exported it externally, and it worked! For others to reference in the future!
//<![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';
}
}
////]]>
John