View Full Version : Using a Range object

06-19-2004, 08:06 AM
Well, I'd like to say I fully understand the range object..but I don't.

At the moment I'm having trouble figuring out how to get a selection using mousedown and mouseup. I can't use the selection object, it won't work in opera.. at least not in the examples I came across.

So my theory was to use the range object for selections use mouse events.
At the moment I have a pitiful theory for a function that will be called on window.load.

It should essentially capture onmousedown and then set the start of the range, then onmouseup set the range end. The problem is, if I understand setStart() and setEnd() properly, they require paramaters..but I don't know what paramters to pass setStart and setEnd.

Ok, what do you guys think about something like:

1) add mousedown and mouseup event handlers to the textarea
maybe something like textarea.addEventListener("mousedown"); etc.

2) On mousedown create a range, setStart(this.mousedown);
//at this point it's guess work for me, I'm not sure how to tell the range
//to start at the mousedown position. I'm not sure what paramater to pass.

3) On mouseup end the range, setEnd(this.mouseup);
//Same thing goes for this part of the script,
//I'm not sure how to tell the range to end at the mouseup position.

4) Use startContainer to make sure actions can only be performed when the
parent container is a textarea.
//I'm guessing this part won't be to difficult, I just hope most browsers
//understand startContainer();.

5) If it was as easy as pseudo code I'd be done by now.. :D

Any help is appreciated...
At the moment I'm just kind of stuck.. don't know where to go from here. And everywhere I look browser compatibility is a big issue. I had hoped to use the selection object.. too bad opera doesn't like it... :confused:

06-19-2004, 10:28 AM
Opera does not support DOM2 Range... nor does it expose any selection objects as a range (as it doesn't support DOM2 Range.... afterall). You're only get Mozilla compatibility with this script, as it is the only browser which implements that much DOM.

06-23-2004, 10:12 AM
There's just no winning is there.. :rolleyes:

Forget Opera, I'm not going to bother to fight my way through this.
I'll instead just have this work on explorer and mozilla.

But what do you think about the steps I've recorded above?
Do they sound like I'm on the right track?

If yes or no, could you or someone with range object experience help me in getting this started. Specifically I would like to figure out how to define the start of a range on mouse down. Mouse up I'm guess will be very similar so I won't need much help there.

Thanks for responding and for letting me know opera doesn't suporrt the range object.
heh heh..opera really doesn't make it easy to create an editor does it.. you can't create a rich text editor because designmode isn't supported, and you can't use the range object..what else is there aside from java and the sort?

once again thanks :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum