Adding an event listener to iframe which has designMode “on” (firefox)

In firefox when designMode is set to “on”, all the events for that iframe are disabled. You cannot add events to that iframe using the convensional way. Actually this makes sense since you wouldn’t want to have mouse hover events or click events triggered when you set the designMode of an iframe to “on”. But not been able to re-enable it while the designMode is still on is really inconvinient. I wanted to add a new feature for the sinhala transliteration for html WYSIWYG editors/RTE (Rich Text Editors). Since the transliteration happens detecting the keypress events in the control i needed to have a number of listeners on an iframe (normally all RTEs use iframe for its designMode functionality). After much searching on the net i found how to do it.

document.getElementById("my_iframe").contentWindow.addEventListener('focus', onFocussed, true)

where ‘focus’ is the event name and  onFocussed is a event handler of the type

function onFocussed(e){
     //Do something
}

Anyones interested my ff addon is here.

Tags: , , ,

2 Responses to “Adding an event listener to iframe which has designMode “on” (firefox)”

  1. http://tinyurl.com/thepdexer28640 Says:

    Just what genuinely moved u to compose “Adding
    an event listener to iframe which has designMode on (firefox) Saminda Wijeratnes Weblog”?

    Idefinitely loved the post! Thanks -Isaac

  2. http://tinyurl.com/phleheney33015 Says:

    How long did it take you to compose “Adding an
    event listener to iframe which has designMode
    on (firefox) Saminda Wijeratnes Weblog”?
    It provides a lot of decent tips. Many thanks ,Kris

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: