The following code checks whether we are in a frame and also makes sure the code get's exectued only if the frame is the second frame in the parents frameset:
if (top !== self && this.window === parent.frames[1]){ alert ('i am in the second frame'); }