Can I manually set selection in document
Can I manually set selection for some part of document?
...in other words somethin' like 'setSelection()' opposite for 'document.getSelection()' method.
In DOM Level 2 specification i find Range object:
myRange = document.createRange();
This object has some methods includin' myRange.setStart(), myRange.setEnd(), which allow manualy set selection.
This object is supported by Opera and FF BUT!!! doesn't supported by IE.
Instead IE has document.selection.createRange() and
document.body.createTextRange();
But how I can set selection in IE??? Is it possible?
TIA
Re: Can I manually set selection in document
First off, getSelection() is a large compatibility problem. Take a look at the chart on this page.
Second, for browsers compatibility you will only be able to select all text within an HTML DOM object.
Re: Can I manually set selection in document
Quote:
Originally Posted by peejavery
Second, for browsers compatibility you will only be able to select all text within an HTML DOM object.
How i can do it? In FF and Opera it's ok, but IE: how i can do it in IE?
THX
Re: Can I manually set selection in document
I already posted the solution. Look at that webpage. Hightlight a selection and click the "Get selection" button. Use getSelection().
Someone else has already solved it for you. It would be a waste of time for me to rewrite that webpage.
Please do not go and edit a post 4 hours after you have already posted. It only succeeds in confusing people. Remember that people will read through this and everything should be in chronological order but will not be if you edit a post 4.5 hours later and after someone else posted after you.
Re: Can I manually set selection in document
Quote:
Originally Posted by peejavery
Please do not go and edit a post 4 hours after you have already posted. It only succeeds in confusing people. Remember that people will read through this and everything should be in chronological order but will not be if you edit a post 4.5 hours later and after someone else posted after you.
Sorry for editin' my 1'st post. I make apology to u ...
Quote:
Originally Posted by peejavery
I already posted the solution. Look at that webpage. Hightlight a selection and click the "Get selection" button. Use getSelection().
But I need to SET selection on page, not GET it.
I wanna to select some word on the page, (word with wrong spelling for ex.)
I know how do it in FF, but don't know how do it in IE.
THX
Re: Can I manually set selection in document
Okay, I am following you now. Below is some code to help you out.
Code:
<html>
<body>
<textarea id="ta" cols=80 rows=10>Test.</textarea>
<script language="JavaScript">
var amount = 4;
var d = document.getElementById('ta');
var oRange = d.createTextRange();
oRange.moveStart("character", 0);
oRange.moveEnd("character", amount - d.value.length);
oRange.select();
d.focus();
</script>
</body>
</html>
Re: Can I manually set selection in document
This code is the 1st realy working thing for IE, I find, thx.
... But Range object in IE can be created only for <input> or <textarea>:(
And if I need to select text in <div>,<p> or another DOM node - method createTextRange() doesn't work.
Probably it's impossible :(
Anyway BIG THX 4U.
Re: Can I manually set selection in document
That is what I was telling you with browser incompatibility. IE is a poor attempt by Microsoft at a web browser. IE7 BETA is pretty good but I use Safari at home and Firefox at work.