How to put target="_blank" at a time for all knowledge article item hyperlinks?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2014 06:36 AM
Hi All,
I have query regarding Knowledge Management. I have some knowledge articles. In those article, I directly enter one hyper link in textarea. If we click in view article and click the link it will open in new window.
My requirement is not for one link. If we have 10 knowledge articles. Each article having so many links. So, I need to go each and every page and put target="_blank" right? But, my concern is, how to put target="_blank" for all hyper links at a time? Please let me know how to do this?
Please let me know the possible solutions.
Many Thanks!
Prasanna Kumar Duvvuri

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2014 03:49 PM
You could run a background script to update all of your KB articles that have 'href=' in them and update the URLs to have the target="_blank" in the url. Something like this:
updateKB();
function updateKB(){
var kb = new GlideRecord('kb_knowledge');
kb.addQuery('text','CONTAINS','href=');
kb.addActiveQuery();
kb.query();
while (kb.next()){
var html = kb.text, counter=0, urlLoc = html.indexOf('href=');
while (urlLoc > -1 && counter < 1){
counter++;
var urlEnd = html.indexOf('">',urlLoc) +1;
var url = html.substring(urlLoc,urlEnd);
var output = html.replace(url,url + ' target="_blank"');
gs.print(output);
kb.text = output;
kb.update();
}
}
}
As a note, I have a counter in my while loop at the moment, which will only run once which I would recommend for testing and then you can remove it afterwards. This was written with the assumption that the links are formatted as: <a title="link title" href="url"> which is how they are formatted when adding an article into the text with the 'insert/edit link' in the KB editor.