Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1391
  • Last Modified:

onkeypress handler for iframe

Hi,

I have an iframe, and I want to call a function when the user is typing inside the iframe. I tried:

<iframe id = "whatever" src="about:blank" onkeypress = "ListenForKeyPress(event);"></iframe>

<script>
function ListenForKeyPress(e)
{
    alert("key pressed in iframe!");
}
</script>

But no messages get caught. Do I need to set the handler for the content window of the iframe or something?

Thanks
0
minnirok
Asked:
minnirok
  • 2
1 Solution
 
bubbledragonCommented:
<iframe id="whatever" designMode="on" src="about:blank" onLoad="setEvent()"></iframe>

<script>
function ListenForKeyPress(e)
{
    alert("key pressed in iframe!");
}

function setEvent() {
document.getElementById('whatever').contentWindow.document.onkeypress = new Function ('ListenForKeyPress(event)');
}
</script>
0
 
bubbledragonCommented:
Hi minnirok,

You must use "Event" Captial for first letter on FF
and "event" all small letter for IE to pass the event.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now