473,414 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

embeding text

Hi,

Little problem...

How to write some text into current document at text coursor position?

Peter
Jul 20 '05 #1
1 1706
Yep
"Piotrek W" <pi********@poczta.onet.pl> wrote in message news:<bg**********@news.onet.pl>...
How to write some text into current document at text coursor position?


You could use some ranges, see below (tested IE5.5 and Mozilla 1.3).
The example uses document.onclick for simplicity, but you could also
use some more advanced triggers (storing the mouse position for IE in
a mousemove handler, and grabbing the rangeParent/rangeOffset from the
mousemove evt object for Gecko).
document.onclick = function(evt){
var d=document;
if(d.selection && d.body && d.body.createTextRange){ //IE
var no_tags="inputtextarea";
if(d.selection.type=="Text" &&
no_tags.indexOf(event.srcElement.nodeName.toLowerC ase())==-1){
var rng=d.body.createTextRange();
rng.moveToPoint(event.x, event.y);
rng.pasteHTML("Foo");
}
}else if(window.getSelection){ //Gecko
var sel=ng=window.getSelection(), rng;
if(sel.rangeCount){
rng=sel.getRangeAt(0);
if(rng.startContainer.nodeType==Node.TEXT_NODE){
var txt=d.createTextNode("Foo"),
txtAfter=rng.startContainer.splitText(rng.startOff set);
txtAfter.parentNode.insertBefore(txt, txtAfter);
sel.removeAllRanges();
}
}
}
}
HTH
Yep.
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Vardhman Jain | last post by:
Hi, I am trying out the concept of python code being executed from a C program. I got a peice of code from the tutorial but I don't know how to compile/use it The code is #include <Python.h> ...
2
by: Sascha Kerschhofer | last post by:
Hi, I am embeding my SVG Files in HTML in this way: <OBJECT DATA="foo.svg" WIDTH="300" HEIGHT="200" TYPE="image/svg+xml"> (using Acrobat SVG Viewer) Since I create the SVG dynamicaly the WIDTH...
2
by: BigOne | last post by:
I'm looking for a script that embeds the text typed on a hidden(and protected) page in to a other page that can be viewed for visitors this text must stay till the owner sets a new text this is...
3
by: Xerxes | last post by:
Hi, I need help in setting up a page where the text wraps around an image. Right now, I am using table, with text in one <td> and the image in the adjacent <td>. The problem is when the text is...
0
by: kiokju | last post by:
I want run Python GUI program on MFC. So I coded this def start(): global Tkinter from Tkinter import * root = Tk() w = Label(root, text="Hello, world!") w.pack()
0
by: mani | last post by:
Hi I'm bringing up an old story once more! I'm on win32 (winxp sp2) python 2.4.4. mingw gcc version is 3.4.5. msys is in c:\msys. mingw is in c:\mingw and python is in c:\pyton24. there is also...
1
by: chazzy69 | last post by:
I know that you can echo html in a .php page, but can you echo html with a javascript aswell? For example Just html echo '<p>' . "hello world" . '</p>'; Then with javascript
1
by: tokcy | last post by:
Hi, I am embeding flash player in my site but i have some problem like... suppose i have 5 songs and i am playing one song but i want to play another while first one is not completed then both...
5
omerbutt
by: omerbutt | last post by:
hi i am trying to use javascript in the anchor tag within the href attribute but it is not picking the value instead it is posting the javascript as a text when i click that link here are the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.