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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

execCommand - Weird result

Status
Not open for further replies.

ScanX

Programmer
Oct 13, 2003
26
BE
Hello,

I'm trying to use the command ID 'Delete' with execCommand but oddly it's deleting too much of my code !!

I'm using a WYSIWYG editor on my webpage...so I'm selecting my image and I click on the "Add/modify link" button.
And at the end I click on OK to apply the modification.

here is in (very) short the end of javascript code :

var GetElem = editdoc.selection.createRange();
GetElem.execCommand('Delete');

when I check what is in GetElem by using GetElem.htmlText I have this :
<A href="../texteleg/etudes/dc050994/chapitre_i.htm#1"><IMG height=16 src="../../Images/retour.gif" width=16 border=0></A>

the "full" HTML from where this comes from is :
<DIV align=center></DIV><A name=1></A><A href="../texteleg/etudes/dc050994/chapitre_i.htm#1"><IMG height=16 src="../../Images/retour.gif" width=16 border=0></A><B><U>Article 1er</U></B>

And the problem is when I do GetElem.execCommand('Delete');
it also deletes the <A name=1></A> !!

Anyone has any idea why the anchor that doesnt seem to be in the range is deleted aswell ?

Thanx in advance for help
 
actually when I use GetElem.execCommand('unlink');
it's the same problem, it's removing both the real link and the anchor
 
I tried the same (IE6) and everything works OK.

Perhaps delete command is too smart and treats named anchor as logical part of next sibling. What happens when you place text node (e.g. single space) between </A> and <A href="...> ?
 
vongrunt I tried what you said and yes when I put a word between </a> and <a href...> it only removes the <a href...> link and the anchor is still there.

You got any clue how to avoid the anchor to be modified ?

thanx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top