das165227
asked on
unlink a hyperlink
heres all the code involved though you probably only need to look at the top function. i'm trying to unlink a hyperlink. the pesky href is still staying around though which makes it still look like a hyperlink. i've tried setting it to "" and to null. any ideas??
function WP_Unlink(wpName) {
HideIfOpen(); // hides menu if open
Backup();
var link= WP_GetClosest(wpName,"a");
if(!link) {
return;
} // end if
link.href= null;
link.style.fontFamily= currentFont;
link.style.fontSize= WP_TranslateFontSize(curre ntFontSize );
editor.focus();
} // end function
function WP_GetClosest(wpName,tagNa me) {
var editor = WP_GetIFrame(wpName);
var ancestors = WP_GetAllAncestors(wpName) ;
var ret = null;
tagName = ("" + tagName).toLowerCase();
for (var i in ancestors) {
var el = ancestors[i];
if (el.tagName.toLowerCase() == tagName) {
ret = el;
break;
}
}
return ret;
}
function WP_GetAllAncestors(wpName) {
editor = WP_GetIFrame(wpName);
var p = WP_GetParentElement(wpName );
var a = [];
while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
a.push(p);
p = p.parentNode;
}
a.push(editor.document.bod y);
return a;
}
function WP_Unlink(wpName) {
HideIfOpen(); // hides menu if open
Backup();
var link= WP_GetClosest(wpName,"a");
if(!link) {
return;
} // end if
link.href= null;
link.style.fontFamily= currentFont;
link.style.fontSize= WP_TranslateFontSize(curre
editor.focus();
} // end function
function WP_GetClosest(wpName,tagNa
var editor = WP_GetIFrame(wpName);
var ancestors = WP_GetAllAncestors(wpName)
var ret = null;
tagName = ("" + tagName).toLowerCase();
for (var i in ancestors) {
var el = ancestors[i];
if (el.tagName.toLowerCase() == tagName) {
ret = el;
break;
}
}
return ret;
}
function WP_GetAllAncestors(wpName)
editor = WP_GetIFrame(wpName);
var p = WP_GetParentElement(wpName
var a = [];
while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
a.push(p);
p = p.parentNode;
}
a.push(editor.document.bod
return a;
}
You might also want to try this:
Change link.href= null; to
link.outerHTML="";
Regards
Change link.href= null; to
link.outerHTML="";
Regards
ASKER
setting it to inner or outer html deletes the whole thing. i'd like to leave the text but if nothing else i can delete the whole thing and put text back in though i'd like the shorter way if there is one
ASKER
that probably didn't make much sense. setting innerHTML or outerHTML= "" made the whole thing disappear but that gives me an idea.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<a href="http://members.aol.com/grassblad" onmouseover='this.outerHTM L=this.inn erHTML'>Gr assBlade</ a>
Vinny
Vinny
To remove a link is not to remove the HREF property.
This is an example showing how to replace a link with its content:
<body>
<a id="te" href="ok">hihi </a>
<script>
function unlinkA(el)
{
document.body.replaceChild (document. createText Node(el.in nerHTML), el);
}
unlinkA(document.getElemen tById('te' ));
</script>
</body>
To remove all links in the document, just do a loop with document.getElementsByTagN ame('A')
This is an example showing how to replace a link with its content:
<body>
<a id="te" href="ok">hihi </a>
<script>
function unlinkA(el)
{
document.body.replaceChild
}
unlinkA(document.getElemen
</script>
</body>
To remove all links in the document, just do a loop with document.getElementsByTagN
ASKER
zyloch thats basically what i ended up doing. i did this before i even read that answer from you. your ealier post about inner and outer html gave me an idea so i did:
function WP_Unlink(wpName) {
HideIfOpen(); // hides menu if open
Backup();
var link= WP_GetClosest(wpName,"a");
if(!link) {
return;
} // end if
link.outerHTML= "<span style= 'font-family:" + currentFont + ";font-size:" + WP_TranslateFontSize(curre ntFontSize ) + "';>" + link.outerText + "</span>";
editor.focus();
} // end function
function WP_Unlink(wpName) {
HideIfOpen(); // hides menu if open
Backup();
var link= WP_GetClosest(wpName,"a");
if(!link) {
return;
} // end if
link.outerHTML= "<span style= 'font-family:" + currentFont + ";font-size:" + WP_TranslateFontSize(curre
editor.focus();
} // end function
You might want to try setting link.href="http://www.google.com/" or "#" just to check if it works. Do some trial and erroring. See if it's one of your other functions. We can probably look through it, but it's so much faster when you narrow it down.
Regards,
Zyloch