Web Analytics Made Easy -
StatCounter Onkeywhatever in CKEditor - CodingForum

Announcement

Collapse
No announcement yet.

Onkeywhatever in CKEditor

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Onkeywhatever in CKEditor

    I've been bashing my head in a vain attempt to achieve the desired result... i.e. having the ability to catch an event inside of an iframe, generated by CKEditor... all in all, I've tried numerous ways to reference the iframe itself, and I've managed to succeed... though catching an event still remains a dream. Google turned out to be less than helpful and well.. CKEditor's own event listeners really don't do a whole lot of good either (Not for me anyways). The code is being tested with the sample provided with the plug-in... for double-click on div to begin editing it. Here is the code I have at the moment:

    Code:
    iframes = document.getElementsByTagName("iframe");
    iframes[0].contentWindow.document.body.onkeypress = function () {
    	alert('Event caught!');
    }
    Obviously, the alert is there for testing purposes, but so far I've been unable to get it to fire. Any help in the matter will be greatly appreciated.
    The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

    How to ask smart questions?

  • #2
    Well, it's definitely been more than 2 days since the original post and no reply, so I felt this deserves a bump. I guess another way to look at the question would be... does anyone know how to catch events inside an IFrame?
    The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

    How to ask smart questions?

    Comment


    • #3
      Well... after revising the code some and generally playing around with it, I came up with the following solution:

      Code:
      function CKeditor_OnComplete() {
          iframes = document.getElementsByTagName("iframe");
          if ( window.addEventListener ) // FireFox and other browsers of the type
              iframes[0].contentWindow.addEventListener('keypress', testy, false);
          else if ( window.attachEvent ) // The root of all evil (IE)
              iframes[0].contentWindow.document.body.attachEvent('onkeypress', testy);
      }
      It seems rather weird how IE and FF handle the attachEvent/addEventListener differently, one having to be targeted towards document.body, the other - towards contentWindow... but hey... that's why we hate IE.

      EDIT: Though for some reason, I can't put the flag Resolved to the topic, (Not having an edit button on the first post) so.... meh.
      Last edited by Eldarrion; Apr 6, 2009, 12:26 PM.
      The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

      How to ask smart questions?

      Comment

      Working...
      X