FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

how can i catch onkeydown event when using frameset

 


afracsass
i created a webpage which has multiple frames with frameset.
But the problem is to catch the onkeydown event.
If i describe this event on the head part of top frameset, nothing happens.
And If i put the script in the child frame the same code sholud be written as many times as the number of frames.

Now I wrote the exatly same code in each frame, and it works but I don't want to keep it in that way cause in case i modify the code i should do it three times.

I hope somebody can help me.

Here's simple example of the code i'm repeating multiple times.

Code:

<script language="javascript">

// function that stops palying when "esc" key is pressed

   function myKeyDown(){
      if(event.keyCode == 27) {
         parent.player.stop();
      }
   }

   document.onkeydown=myKeyDown;
</script>


thanx,
Stubru Freak
Have you tried:

Code:
document.getElementById("frameID1").onkeydown=myKeyDown;
document.getElementById("frameID2").onkeydown=myKeyDown;
document.getElementById("frameID3").onkeydown=myKeyDown;
document.getElementById("frameID4").onkeydown=myKeyDown;
document.getElementById("frameID5").onkeydown=myKeyDown;
document.getElementById("frameID6").onkeydown=myKeyDown;
afracsass
No i didn't.
Let me try and tell you what happens.
bytheway,
i realy appreciate your prompt advice. this forum is so cool ! i feel like i'd really get to like this forum Laughing
Nyizsa
You can either put your script in a .js file and reference it from every frame, or pass the event from the child-frame to the top-frame. I think the first one is easier and makes more sense.
afracsass
Stubru Freak wrote:
Have you tried:

Code:
document.getElementById("frameID1").onkeydown=myKeyDown;
document.getElementById("frameID2").onkeydown=myKeyDown;
document.getElementById("frameID3").onkeydown=myKeyDown;
document.getElementById("frameID4").onkeydown=myKeyDown;
document.getElementById("frameID5").onkeydown=myKeyDown;
document.getElementById("frameID6").onkeydown=myKeyDown;


Looks like this script does not work.

I was thinking common js file to include for each frame but looks like it'll create much more mess. some script are common and some aren't.

Instead i think i'd better rewrite whole code without frame.

Now i can understand why people don't like to use frameset. This is really pain in the ?ss. One frame structure is the solution i think.

Thanks have nice day!
Nyizsa
afracsass wrote:
I was thinking common js file to include for each frame but looks like it'll create much more mess. some script are common and some aren't.

Never mind that - put everything there, and you will have some functions that you call only from one page. This will be a fast soultion. But it is a good idea to rewrite it without frames - divs maybe?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.