PDA

View Full Version : remove href tags from links



drsanupmoideen
08-10-2010, 09:08 PM
Hello Everybody, For my site, I would like to remove the href tags from all links created by users. So i added the following code to the header session of my site.

<script type="text/javascript">
jQuery(document).ready(function($) {
$("a").filter(function() {
return this.hostname && this.hostname !== location.hostname;
}).addClass('external').attr("target", "_blank").removeAttr('href');
});
</script>

Its working fine, except that, it also removes the links to my subdomains. Can anybody please help me? I just want to remove the href tag only from contents inside a particular div "pagebody".

Thankyou all :)

azoomer
08-10-2010, 09:28 PM
If the particular div you want to target has the id="pagebody" you could do something like this

<script type="text/javascript">
jQuery(document).ready(function($) {
$("#pagebody a").filter(function() {
return this.hostname && this.hostname !== location.hostname;
}).addClass('external').attr("target", "_blank").removeAttr('href');
});
</script>

drsanupmoideen
08-10-2010, 09:43 PM
Thank you azoomer, it worked. :)

drsanupmoideen
08-11-2010, 01:39 PM
Is it possible to add some exclusions to this? Just like, if the link url == googel.co/ wikipedia.com etc, dont strip the href tags?