views:

537

answers:

2

I have an Iframe which I have enabled designMode on. Quite simply I would like to have a callback function called if the cursor in the Iframe moves or content changes. It seemed quite simple at first but I can't use onchange/ onkeyup on the Iframe.

I assume I need to add an event to a member of the Iframe. I've tried

frames['writer'].document.body.onkeyup = eventHandler

to no success.


Update

I've found that setting designMode = 'on' is causing the problems. If I comment out the line that sets designMode to 'on' then handling events works fine.

A: 

Try writing a function called document.onkeyup:

function document.onkeyup() {
  // do stuff
}

I've never seen that style before, but that was just something I found on Google...

Deniz Dogan
+1  A: 

OK, I have a solution:

if(document.addEventListener)
{
    frames['writer'].document.addEventListener('keyup', updateStatus, false);
    frames['writer'].document.addEventListener('mouseup', updateStatus, false);
}

It works a charm!