Getting HTML from a users text selection

A

Andrew Crowe

Hi guys,

Using the following function

function class_getSelection(){
if (browser.isIE5up) {
return EpozElement.contentWindow.document.selection;
} else {
return EpozElement.contentWindow.window.getSelection();
};
}

I can get the text that a user has selected on a page.

However it parses out all the html and just returns the selection as
plain text. Is there any way to return the users selection including any
HTML tags.
 
R

rf

Andrew Crowe said:
Hi guys,

Using the following function

function class_getSelection(){
if (browser.isIE5up) {
return EpozElement.contentWindow.document.selection;
} else {
return EpozElement.contentWindow.window.getSelection();
};
}

I can get the text that a user has selected on a page.

However it parses out all the html and just returns the selection as
plain text. Is there any way to return the users selection including any
HTML tags.

Why?
 
R

rf

Andrew said:
I'm customizing a browser based WYSIWYG editor and would like to do
operations that aren't supported by any execCommand commands

Since this is obviously IE stuff you are probably better off visiting their
newsgroups.

I have played with (what I am assuming you are using) mshtml.dll but not to
this extent.

BTW wysiwyg usually equates to wysiwyng, the n meaning "Never get in other
browsers".
 
A

Andrew Crowe

Since this is obviously IE stuff you are probably better off visiting their
newsgroups.

I have played with (what I am assuming you are using) mshtml.dll but not to
this extent.

BTW wysiwyg usually equates to wysiwyng, the n meaning "Never get in other
browsers".

Ah no I don't mean an editor application, I mean an editable content
area in a webpage. (it's similar to http://kupu.oscom.org/)

I'd also need to to work in both IE and Mozilla
 
C

Chris Morris

rf said:
Since this is obviously IE stuff you are probably better off visiting their
newsgroups.

It's not. I've done similar things myself (though this problem is out
of my depth) and they work as well (or occasionally better...) in
recent Mozilla (1.3+). Opera, Konqueror, etc. don't support the
necessary Javascript, so it's back to a normal <textarea> for them [1].

[1] Which is useful in w3m since that passes textareas off to
text-editor-of-choice and a pain in everything else.
It's only semi-useful in everything else since the output of
execCommand-based editors often needs a lot of cleaning up.
 
J

Jim Higson

Andrew said:
Ah no I don't mean an editor application, I mean an editable content
area in a webpage. (it's similar to http://kupu.oscom.org/)

demo here:
http://philikon.de/files/kupu/common/kupu.html

Certainly impressive, but how is this editor done? Is it pure
html+javascript or is there more involved such as special browser
'extensions'?

I'm guessing it just creates a bunch of normal input elements and
adds/removes edited content using DHTML.

Jim
 
A

Andrew Crowe

Jim Higson wrote:

demo here:
http://philikon.de/files/kupu/common/kupu.html

Certainly impressive, but how is this editor done? Is it pure
html+javascript or is there more involved such as special browser
'extensions'?

I'm guessing it just creates a bunch of normal input elements and
adds/removes edited content using DHTML.

Basically IE and Mozilla allow you to set a div as "editable", which
lets users edit their content using the browsers own HTML editors (this
works on anything without javascript).

The Bold/Italic controls etc. are handled by special javascript calls
relating to the editable areas.

For more information see
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/contenteditable.asp


Andrew
 
J

Jim Higson

Basically IE and Mozilla allow you to set a div as "editable", which
lets users edit their content using the browsers own HTML editors (this
works on anything without javascript).

Ok, when I first saw the editor I thought of using like this for a project
I'm working on, but now I've read this I think I'll stick to more
accessable solutions. Besides, this is somewhat inflexable in that it
allows WYSIWYG editing of html, but not any other formats (at least not
without messy conversion).
The Bold/Italic controls etc. are handled by special javascript calls
relating to the editable areas.

For more information see
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/contenteditable.asp

"There is no public standard that applies to this property."

Not a terrible thing in itself, but I'll pass.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,196
Latest member
ScottChare

Latest Threads

Top