|
-
August 2nd, 2006, 10:07 AM
#1
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
Last edited by =vd=; August 2nd, 2006 at 02:23 PM.
-
August 2nd, 2006, 01:59 PM
#2
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.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
August 2nd, 2006, 02:36 PM
#3
Re: Can I manually set selection in document
 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
-
August 2nd, 2006, 02:51 PM
#4
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.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
August 2nd, 2006, 03:15 PM
#5
Re: Can I manually set selection in document
 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 ...
 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
-
August 2nd, 2006, 05:16 PM
#6
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>
Last edited by peejavery; August 2nd, 2006 at 05:19 PM.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
August 3rd, 2006, 02:48 AM
#7
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.
-
August 3rd, 2006, 01:54 PM
#8
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.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|