Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a range from nothing?

Status
Not open for further replies.

stormbind

Technical User
Joined
Mar 6, 2003
Messages
1,165
Location
GB
Here's an example from Microsoft:

====================================
var sel = document.selection;

if (sel!=null) {
var rng = sel.createRange();
if (rng!=null)
rng.pasteHTML('<HTML></HTML>');
}
====================================

Problems:

1) The above causes an &quot;unspecified error&quot; if the selection is null. It would be nice if microsoft's error could be removed.

2) What I'm really looking for is a means of pasting HTML beside the cursor when the user has made no selection.

Any ideas? :(

Lastly, can anyone describe clearly the difference between a text range and a control range? I'm under the impression that the former is plain text, and the latter is HTML tags but I'm not sure.
 
for #1, try:

var sel = document.selection;

if (sel) {
var rng = sel.createRange();
if (rng)
rng.pasteHTML('<HTML></HTML>');
}

#2 is more complicated, and i'm going to lunch right now ;-)

=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
I know it's more complicated, that why I posted it ;)

I have still not solved it. Desperately need help. Not sure if I have done it before or not; this makes it doubly frustrating! :[
 
It almost helped but it would seem that solution doesn't work with DOM.

My editable region is a DIV tag, not a TEXTAREA.

Getting the claret position is a big stumbling block for me atm :(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top