Trying to duplicate createTextRange functions

L

laredotornado

Hi,

I am trying to make some IE-only JScript work on Firefox and Safari.
Does anyone know of equivalent methods for these functions?

document.selection.createRange()
document.body.createTextRange()

It is only necessary that any equivalent functions work on the lateset
versions of Firefox and Safari. Thanks, -
 
R

Randy Webb

(e-mail address removed) said the following on 7/14/2006 10:45 AM:
Hi,

I am trying to make some IE-only JScript work on Firefox and Safari.
Does anyone know of equivalent methods for these functions?

document.selection.createRange()
document.body.createTextRange()

There aren't any.
 
R

RobG

Hi,

I am trying to make some IE-only JScript work on Firefox and Safari.
Does anyone know of equivalent methods for these functions?

document.selection.createRange()
document.body.createTextRange()

It is only necessary that any equivalent functions work on the lateset
versions of Firefox and Safari. Thanks, -

There is no direct equivalent, however you should be able to emulate it
using window.getSelection and the range object:

<URL:http://developer.mozilla.org/en/docs/DOM:window.getSelection>


At the bottom of the page that the above URL links to are links to
selection and range.

window.getSelection is DOM 0, it is supported by Safari (I tested 2.0.4)
however I couldn't get it to work using Firefox 1.5.0.4 (Mac OS) even
though the Gecko DOM reference indicates that it should - as soon as you
click on a button, the selection is lost:

<p>Here is some text</p>
<input type="button" value="Show selection" onclick="
if ('function' == typeof window.getSelection){
var t = window.getSelection();
alert(t);
">
 
R

RobG

RobG wrote:
[...]
window.getSelection is DOM 0, it is supported by Safari (I tested 2.0.4)
however I couldn't get it to work using Firefox 1.5.0.4 (Mac OS) even
though the Gecko DOM reference indicates that it should - as soon as you
click on a button, the selection is lost:

I tested 1.5.0.4 on Windows and it's broken too. It appears to be fixed
in the latest nightly build, I don't know when that will make it into
the production version - maybe wait for 2.0?

<URL:http://wiki.mozilla.org/Firefox:2.0_Product_Planning>
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top