Connecting Tech Pros Worldwide Help | Site Map

Capturing the onkeydown event i an IFRAME.

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 20th, 2005, 10:29 AM
Tobias Åkeblom
Guest
 
Posts: n/a
Default Capturing the onkeydown event i an IFRAME.

I have a mainpage where i display my menu and an iframe for the
content to load in. I want to trace keydown events i the Iframe. This
works well the first time I load the site. But when I load new content
in the iframe it seems like the eventlistner is destroyed. I can´t
really understand why. Because the onkeydown listner in the mainpage
is untouched.

Here is the code. Is there a solution to my problem?

<body>
<div id="appCont" style="position:absolute;top:5px;left:5px">
<iframe
scrolling="no"
name="appFrame"
src="splash.jsp"
frameborder="0"
width="990"
height="740">
</iframe>
</div>
<script type="text/javascript">
frames[0].document.onkeydown = function (evt) {
whichASC=(bw.ie)?frames[0].event.keyCode:evt.which;
alert(whichASC)
if(whichASC==81) {
ctrlPressed = true;
return false;
}
if(whichASC==9 && ctrlPressed) {
//do something
}
return true;
};
</script>
</body>

  #2  
Old July 20th, 2005, 10:30 AM
Dale Hurtt
Guest
 
Posts: n/a
Default Re: Capturing the onkeydown event i an IFRAME.

On 15 Sep 2003 08:00:17 -0700, tobias.akeblom@zait.se (Tobias Åkeblom)
wrote:
[color=blue]
>But when I load new content
>in the iframe it seems like the eventlistner is destroyed. I can´t
>really understand why. Because the onkeydown listner in the mainpage
>is untouched.[/color]
[color=blue]
> frames[0].document.onkeydown = function (evt) {[/color]

Just a wild guess, but you are attaching the function to the
frames[0].document NODE and when you change locations the document is
destroyed and a new one re-created.

Try re-attaching the function to the new frames[0].document every time
you change locations. I suspect that might fix it.

Dale Hurtt
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.