How can you remove the # (anchor tag) from the URL

Jessica S
Tera Contributor

We have knowledge articles that utilize anchor tags, however, we want to remove the # that is added to the URL when the user clicks on the bookmark links.

Current Result:

https://.service-now.com/sys_id=5eafb51537df79807cae27d2b3990e77d&table=kb_knowledge#TableOfContents

Desired Result: 

https://.service-now.com/sys_id=5eafb51537df79807cae27d2b3990e77d&table=kb_knowledge

Thanks in advance for your help,

Jessica

3 REPLIES 3

Alikutty A
Tera Sage

Hello,

How are the articles bookmarked? If you need to correct these bookmarks, navigate to sys_ui_bookmark table, locate all bookmarks related to your kb_knowledge with a # in it and you could update the URL in here.

SaiRaviKiran Ak
Giga Guru

How are you making articles bookmarked ?

also can you share your widget code?

Jessica S
Tera Contributor

Anchor tags are placed directly in the HTML of the KB Articles.

For example: 

<p><span style="font-size: 12pt;">To apply for benefits, please contact your state's administrator (<a href="#SDIAdministrator" rel="nofollow">below</a>). Benefits are not automatic; if you do not apply, you will not receive benefits.</span></p>

 

Widget - Link field - This custom code was added by a previous vendor to remove the anchor tags (#) from appearing in the URL. However, it is not working as expected. When click on the link from the HTML above the page does not scroll to the current section in the article. We attempted to remove this code, but that resulted in the anchor tags to appear in the URL which is not what we want our end users to see.

function(scope, element, attrs) {
setTimeout(function(){
var el = $(element[0]);
$(el).find('*[href=\\#TableOfContents]').on('click', function() {
scope.scrollToTop();
});
},500);
setTimeout(function(){
$('a[href^="#"]').on('click', function(event) {
var target = $(this.getAttribute('href'));

if( target.length ) {
event.preventDefault();
$('.flex-grow').stop().animate({
scrollTop: target.offset().top - 200
}, 100);
}
});
},500);

}