0

How would I go about simulating a keypress within my editable iframe? (Same domain.)

The iframe has designmode on, and the body is being used as a text field for an RTE.

I have a feeling I need to use the trigger function from jquery, but I am unable to get it to work.

$('#editor body').trigger({type: 'keypress', which: 13, keyCode: 13});

EDIT: Apparently this isn't possible. Is there any way to make an iframe scroll to the cursor's position without pressing a key?

Clint
  • 169
  • 1
  • 12
  • http://stackoverflow.com/questions/364952/jquery-javascript-accessing-contents-of-an-iframe?rq=1 – Gary Hayes Feb 17 '15 at 00:01
  • http://stackoverflow.com/questions/24688268/can-a-button-click-cause-an-event-in-iframe/24689865#24689865 – guest271314 Feb 17 '15 at 01:07
  • Guest, thats pretty much perfect. Does it work for iframes in the HTML code or does the iframe have to be added via jquery? – Clint Feb 17 '15 at 05:40

1 Answers1

1

You can't do it with events. Events don't cause keypresses. Keypresses cause events.

WYSIWYG editors have an API that you can use to interact with the editor.


However, if you really need to fire events, then the problem can be broken down into two that already have answers:

Community
  • 1
  • 1
Kornel
  • 97,764
  • 37
  • 219
  • 309
  • Oh. I thought it was possibly to simulate an event using jquery. Is there any way to mimic an arrow key after running a function? (Move the caret over 1 position). – Clint Feb 17 '15 at 00:06
  • When searching for ways to have the area scroll to the caret I was given solutions such as this http://stackoverflow.com/questions/686053/keeping-caret-position-in-a-visible-position-in-text-input-firefox-misbehaves which tells the user to fake a keypress. I have already created a custom editor (Which works great with the only bug being scrolling and undo) so I wish to keep using it rather than swap to a different editor. Is there a more valid way to achieve the scroll? – Clint Feb 17 '15 at 00:21