Need help stopping script from executing when not in frames!

JavaScript and client side scripting.

Moderator: General Moderators

Need help stopping script from executing when not in frames!

Postby JAB Creations » Sun Jan 29, 2006 10:04 pm

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.

Syntax: [ Download ] [ Hide ]
//<![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
User avatar
JAB Creations
DevNet Resident
 
Posts: 2341
Joined: Thu Jan 13, 2005 7:44 pm
Location: Sarasota Florida

Postby feyd » Sun Jan 29, 2006 10:19 pm

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



maybe?
User avatar
feyd
Neighborhood Spidermoddy
 
Posts: 31559
Joined: Mon Mar 29, 2004 4:24 pm
Location: Bothell, Washington, USA

Postby JAB Creations » Sun Jan 29, 2006 10:24 pm

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
User avatar
JAB Creations
DevNet Resident
 
Posts: 2341
Joined: Thu Jan 13, 2005 7:44 pm
Location: Sarasota Florida

Script Solved!

Postby JAB Creations » Mon Jan 30, 2006 1:17 am

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
User avatar
JAB Creations
DevNet Resident
 
Posts: 2341
Joined: Thu Jan 13, 2005 7:44 pm
Location: Sarasota Florida


Return to Javascript

Who is online

Users browsing this forum: Bing [Bot] and 4 guests