Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #23103 > unrolled thread

Why insert goes to next line instead of current cursor position

Started byjustaguy <lichunshen84@gmail.com>
First post2014-02-15 17:52 -0800
Last post2014-02-16 19:55 +0100
Articles 6 — 4 participants

Back to article view | Back to comp.lang.javascript


Contents

  Why insert goes to next line instead of current cursor position justaguy <lichunshen84@gmail.com> - 2014-02-15 17:52 -0800
    Re: Why insert goes to next line instead of current cursor position Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-16 03:09 +0100
      Re: Why insert goes to next line instead of current cursor position justaguy <lichunshen84@gmail.com> - 2014-02-15 18:50 -0800
        Re: Why insert goes to next line instead of current cursor position Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-16 11:01 +0100
          Re: Why insert goes to next line instead of current cursor position John Harris <niam@jghnorth.org.uk.invalid> - 2014-02-17 10:12 +0000
    Re: Why insert goes to next line instead of current cursor position Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-16 19:55 +0100

#23103 — Why insert goes to next line instead of current cursor position

Fromjustaguy <lichunshen84@gmail.com>
Date2014-02-15 17:52 -0800
SubjectWhy insert goes to next line instead of current cursor position
Message-ID<31cd8077-c866-4dcb-8f0b-498dc52e2824@googlegroups.com>
Hi,

I have an iframe with id of "frameID" and I'd like to insert something into this iframe at its current cursor position (the iframe has some content already).  So, it looks like this:
<iframe id="iframeID"...>my iframe content here...</iframe>

The js function code looks like this. 

function insertAtCursorPos(stuff) {
	var f = document.getElementById('frameID');
		var fc = (f.contentDocument || f.contentWindow.document);
		if (fc) {
		fc.body.innerHTML = Ed.body.innerHTML + ' ' + stuff; 
		}

I guess the problem lies in the last line, which appends the value of the function param stuff.  And currently, the insertion goes to next line, instead of the very end of the iframe content.

So, how do we specify the current cursor position of an iframe?

Many thanks.

[toc] | [next] | [standalone]


#23105

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-02-16 03:09 +0100
Message-ID<1570702.W5tESRjSNo@PointedEars.de>
In reply to#23103
justaguy wrote:

> I have an iframe with id of "frameID" and I'd like to insert something
> into this iframe at its current cursor position (the iframe has some
> content already).  So, it looks like this: <iframe id="iframeID"...>my
                                                         ^^^^^^^^
> iframe content here...</iframe>
> 
> The js function code looks like this.
> 
> function insertAtCursorPos(stuff) {
> var f = document.getElementById('frameID');
                                   ^^^^^^^ ID mismatch
> var fc = (f.contentDocument || f.contentWindow.document);
> if (fc) {
> fc.body.innerHTML = Ed.body.innerHTML + ' ' + stuff;

What is “Ed”?

> }
> 
> I guess […]

Please don't.  Use a debugger instead, finally.

<http://www.catb.org/~esr/faqs/smart-questions.html>

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#23106

Fromjustaguy <lichunshen84@gmail.com>
Date2014-02-15 18:50 -0800
Message-ID<2eec8d0c-4e94-4ef3-af37-a3e59f53768b@googlegroups.com>
In reply to#23105
On Saturday, February 15, 2014 9:09:37 PM UTC-5, Thomas 'PointedEars' Lahn wrote:
> justaguy wrote:
> 
> 
> 
> > I have an iframe with id of "frameID" and I'd like to insert something
> 
> > into this iframe at its current cursor position (the iframe has some
> 
> > content already).  So, it looks like this: <iframe id="iframeID"...>my
> 
>                                                          ^^^^^^^^
> 
> > iframe content here...</iframe>
> 
> > 
> 
> > The js function code looks like this.
> 
> > 
> 
> > function insertAtCursorPos(stuff) {
> 
> > var f = document.getElementById('frameID');
> 
>                                    ^^^^^^^ ID mismatch
> 
> > var fc = (f.contentDocument || f.contentWindow.document);
> 
> > if (fc) {
> 
> > fc.body.innerHTML = Ed.body.innerHTML + ' ' + stuff;
> 
> 
> 
> What is "Ed"?
> 

Sorry, typo, 
> fc.body.innerHTML = Ed.body.innerHTML + ' ' + stuff;
should have been
> fc.body.innerHTML = fc.body.innerHTML + ' ' + stuff;

[toc] | [prev] | [next] | [standalone]


#23107

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-02-16 11:01 +0100
Message-ID<7374037.s4EfTAcK1v@PointedEars.de>
In reply to#23106
justaguy wrote:

[fixed quotation having attribution novel and interleaved empty lines]

> [..] Thomas 'PointedEars' Lahn wrote:
>> justaguy wrote:
>> > I have an iframe with id of "frameID" and I'd like to insert something
>> > into this iframe at its current cursor position (the iframe has some
>> > content already).  So, it looks like this: <iframe id="iframeID"...>my
>>                                                          ^^^^^^^^
>> > iframe content here...</iframe>
>> > 
>> > The js function code looks like this.
>> > 
>> > function insertAtCursorPos(stuff) {
>> > var f = document.getElementById('frameID');
>>                                    ^^^^^^^ ID mismatch
>> > var fc = (f.contentDocument || f.contentWindow.document);
>> > if (fc) {
>> > fc.body.innerHTML = Ed.body.innerHTML + ' ' + stuff;
>> 
>> What is "Ed"?
> 
> Sorry, typo,
>> fc.body.innerHTML = Ed.body.innerHTML + ' ' + stuff;
> should have been
>> fc.body.innerHTML = fc.body.innerHTML + ' ' + stuff;

OK, but as long as there is the ID mismatch, it is not going to work because 
execution will not reach that line.

Use a fixed-width font for display.  And not the b0rken, spammed Google 
Groups for posting to Usenet.  Probably someone has told you that before.

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#23115

FromJohn Harris <niam@jghnorth.org.uk.invalid>
Date2014-02-17 10:12 +0000
Message-ID<13o3g9tjnsm9abdbj1c37kopbqilm0f05n@4ax.com>
In reply to#23107
Thomas wrote:

>justaguy wrote:
  <snip>

When? Where?

Think : what happens if your article is copied into a blog ?

  John

[toc] | [prev] | [next] | [standalone]


#23114

FromChristoph Michael Becker <cmbecker69@arcor.de>
Date2014-02-16 19:55 +0100
Message-ID<530109bc$0$6656$9b4e6d93@newsspool2.arcor-online.net>
In reply to#23103
justaguy wrote:

> So, how do we specify the current cursor position of an iframe?

Basically, the same way as done for the document.  If I'm not mistaken,
there is no API to find the current cursor position, *generally* (after
all, there's no cursor for most elements).

However, it occurs to me that you might be dealing with an iframe where
the designMode property is set to true.  If so, you should have a look
at the rich text editing[1] API of the browsers.

[1] <https://developer.mozilla.org/de/docs/Rich-Text_Editing_in_Mozilla>

-- 
Christoph M. Becker

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web