View Full Version : insert obj inside a range obj

11-24-2004, 01:56 PM
I would like to insert an object inside a range object, at a desired cursor position, crossbrowser

I have so far (function is fired onclick="insertObj(event)" )

<script language="JavaScript" type="text/JavaScript">
function insertObj(e){
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
if (e.pageX || e.pageY)
posx = e.pageX;
posy = e.pageY;
else if (e.clientX || e.clientY)
posx = e.clientX;
posy = e.clientY;
var r= document.getElementsByTagName('body')[0].createTextRange();
var r=document.createRange();
var t=document.createTextNode('BLA');//the object to be inserted
r.insertNode(t)//this works for Moz only. Anyway the insertion is at the beginig of range object

I have two problems now.

Q1. Which method could be IE equivalent of insertNode()?
Q2. How can I insert the object at the desired mouse posx, posy (insert an object onclick at the cursor's position)? IE has some method as moveToPoint(), but I can not verify until I find the answer at Q1.

Any ideeas?