<DIV align=left><FONT size=2>I encountered a problem when I tried to modify the attribute (href, target, etc.) of a exist link: the editor inserts a new <A></A> element between my original link with the new attributes, but not changes the attribute of the exist <A></A> element.<BR>
<BR>
Im using the 0.18b release edition, but i get the same problem in the later release.<BR>
</FONT><FONT size=2><BR>
So I hacked the code to fit my need. here is what i did:</FONT></DIV>
<DIV align=left>
<TABLE class="" style="WIDTH: 100%; HEIGHT: 100%" border=1 maxcols="1">
<TBODY>
<TR>
<TD>
<P>
function c_link( e, v ) {<BR>
/*====================================<BR>
* get the correct parentElemnt of the link<BR>
*====================================*/<BR>
var start = d.selection.createRange().parentElement();<BR>
while((start!=null) && (start.tagName != "A")) {<BR>
start = start.parentElement;<BR>
}<BR>
/*====================================<BR>
* expand the selection to the whole content of the link<BR>
*====================================*/<BR>
if( start ) {<BR>
var r = d.body.createTextRange();<BR>
r.findText( start.innerText );<BR>
r.select();<BR>
}</P>
Sorry! I copied and pasted the source code from my editor directly! What I want to say is:
I encountered a problem when I tried to modify the attribute (href, target, etc.) of a exist link: the editor inserts a new <A></A> element between my original link with the new attributes, but not changes the attribute of the exist <A></A> element.
Im using the 0.18b release edition, but i get the same problem in the later release.
So I hacked the code to fit my need. here is what i did:
function c_link( e, v ) {
/*====================================
* get the correct parentElemnt of the link
*====================================*/
var start = d.selection.createRange().parentElement();
while((start!=null) && (start.tagName != "A")) {
start = start.parentElement;
}
/*====================================
* expand the selection to the whole content of the link
*====================================*/
if( start ) {
var r = d.body.createTextRange();
r.findText( start.innerText );
r.select();
}
if( v ) {
lnk.href = v.href;
lnk.target = v.target;
}
/*====================================
* get the attribute of the link
*====================================*/
else if( start ) {
lnk.href = start.href;
lnk.target = start.target;
lnk.innerHTML = start.innerText;
} else {
lnk.href = '';
lnk.target = '_blank';
lnk.innerHTML = range().htmlText;
}
<DIV align=left><FONT size=2>I encountered a problem when I tried to modify the attribute (href, target, etc.) of a exist link: the editor inserts a new <A></A> element between my original link with the new attributes, but not changes the attribute of the exist <A></A> element.<BR>
<BR>
Im using the 0.18b release edition, but i get the same problem in the later release.<BR>
</FONT><FONT size=2><BR>
So I hacked the code to fit my need. here is what i did:</FONT></DIV>
<DIV align=left>
<TABLE class="" style="WIDTH: 100%; HEIGHT: 100%" border=1 maxcols="1">
<TBODY>
<TR>
<TD>
<P>
function c_link( e, v ) {<BR>
/*====================================<BR>
* get the correct parentElemnt of the link<BR>
*====================================*/<BR>
var start = d.selection.createRange().parentElement();<BR>
while((start!=null) && (start.tagName != "A")) {<BR>
start = start.parentElement;<BR>
}<BR>
/*====================================<BR>
* expand the selection to the whole content of the link<BR>
*====================================*/<BR>
if( start ) {<BR>
var r = d.body.createTextRange();<BR>
r.findText( start.innerText );<BR>
r.select();<BR>
}</P>
<P>
if( v ) {<BR>
lnk.href = v.href;<BR>
lnk.target = v.target;<BR>
}<BR>
/*====================================<BR>
* get the attribute of the link<BR>
*====================================*/<BR>
else if( start ) {<BR>
lnk.href = start.href;<BR>
lnk.target = start.target;<BR>
lnk.innerHTML = start.innerText;<BR>
} else {<BR>
lnk.href = '';<BR>
lnk.target = '_blank';<BR>
lnk.innerHTML = range().htmlText;<BR>
}<BR>
<BR>
lnk.anchors = d.anchors;<BR>
var a = showModalDialog( path + 'aiLink.html', lnk, 'scroll:0;help:0;status:0;dialogWidth:400px;dialogHeight:275px;' );<BR>
if( a ) {<BR>
var r = range();<BR>
if( r.control ) {<BR>
r.item(0).applyElement( d.createElement( '<a href="' + a.href + '" target="' + a.target + '">' ) );<BR>
} else {<BR>
r.pasteHTML( '<a href="' + a.href + '" target="' + a.target + '" >' + a.innerHTML + '</a>' );<BR>
}<BR>
}<BR>
}</P>
</TD>
</TR></TBODY></TABLE></DIV>
Sorry! I copied and pasted the source code from my editor directly! What I want to say is:
I encountered a problem when I tried to modify the attribute (href, target, etc.) of a exist link: the editor inserts a new <A></A> element between my original link with the new attributes, but not changes the attribute of the exist <A></A> element.
Im using the 0.18b release edition, but i get the same problem in the later release.
So I hacked the code to fit my need. here is what i did:
function c_link( e, v ) {
/*====================================
* get the correct parentElemnt of the link
*====================================*/
var start = d.selection.createRange().parentElement();
while((start!=null) && (start.tagName != "A")) {
start = start.parentElement;
}
/*====================================
* expand the selection to the whole content of the link
*====================================*/
if( start ) {
var r = d.body.createTextRange();
r.findText( start.innerText );
r.select();
}
if( v ) {
lnk.href = v.href;
lnk.target = v.target;
}
/*====================================
* get the attribute of the link
*====================================*/
else if( start ) {
lnk.href = start.href;
lnk.target = start.target;
lnk.innerHTML = start.innerText;
} else {
lnk.href = '';
lnk.target = '_blank';
lnk.innerHTML = range().htmlText;
}
lnk.anchors = d.anchors;
var a = showModalDialog( path + 'aiLink.html', lnk, 'scroll:0;help:0;status:0;dialogWidth:400px;dialogHeight:275px;' );
if( a ) {
var r = range();
if( r.control ) {
r.item(0).applyElement( d.createElement( '<a href="' + a.href + '" target="' + a.target + '">' ) );
} else {
r.pasteHTML( '<a href="' + a.href + '" target="' + a.target + '" >' + a.innerHTML + '</a>' );
}
}
}