Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: DHTML
Expertise: Beginner
Nov 3, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Replace Selected Content


How do I replicate the pasteHTML function supported by Internet Explorer in Netscape? Rewriting the layer isn't the problem. The problem is determining the position of the text returned by the getSelection(). For example, how would I allow a user to select a piece of text on the screen and modify it (i.e. make it bold)? If the selected word appears more than once in the text, I can't just find() it.


You will not be able to do what you want with Navigator. IE supports replacement of the selected content. Navigator 4.x does not. All you can do to replace the contents with Navigator (at least with Navigator 4.x at this time) is to use document.write to a positioned DIV or SPAN block, or to a layer. You won't be able to replace content based on a person selecting text from the page.

The best you can hope for is layer your entire Web page, capture the mouse click events for each layer, and when the person "applies" something to the selection, recreate the entire block, but this time add the strong tags ("") to the "selected" content. This means you would need to be able to recreate each layer, so you're probably looking at putting page content into an array for just this purpose. This could be messy, but it is a place for you to start if you absolutely have to have this type of functionality.

DevX Pro
Thanks for your registration, follow us on our social networks to keep up-to-date