JavaScript and client side scripting.
Moderator: General Moderators
JAB Creations
DevNet Resident
Posts: 2341 Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:
Post
by JAB Creations » Sun Jan 29, 2006 9: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.
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jan 29, 2006 9:19 pm
Code: Select all
if( typeof parent == 'object' ) {
if( typeof parent.border != 'undefined' ) {
parent.frames['border'].location = //
}
}
maybe?
JAB Creations
DevNet Resident
Posts: 2341 Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:
Post
by JAB Creations » Sun Jan 29, 2006 9: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
JAB Creations
DevNet Resident
Posts: 2341 Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:
Post
by JAB Creations » Mon Jan 30, 2006 12: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