Open Suggested Articles in New Window | Community
Skip to main content

Open Suggested Articles in New Window

  • January 3, 2024
  • 2 replies
  • 0 views

In Guide when filling out the form inside the "New Request" page it presents users with Suggested articles. Is is possible to open the suggested article in a new window? Currently it opens in the same window moving you away from the form (which you might have already started to fill out).

I am guessing I can add a property inside the HTML or Javascript in the template? I just can't fine the element and what to add.

Thank you!

2 replies

Hi Anton,
 
There isn't a native way to open the suggested articles in a new tab on click, past right clicking the link and opening in a new tab. However you can use the below script to achieve this, you just need to paste the below code in script.js folder in Guide theme
 
window.addEventListener('load', () => { 
//  Get suggestion list element
  const suggestion_list = document.querySelector(".suggestion-list"); 
  
// MutationObserver to watch for changes to the DOM at the suggestion list div
// and add required elements to dynamically generated links
  const config = { attributes: true, childList: true, subtree: true };
    let suggestionObserver = new MutationObserver((list) => {
    if(list[0].target == suggestion_list){
    // Creates variables if suggestion list children have been populated to the DOM      
      if(suggestion_list.childNodes){
            const searchbox_suggestions = document.querySelector(".searchbox-suggestions");
            const search_list = searchbox_suggestions.children[0];        
        // Adds attributes if suggested article links have been populated to the DOM          
          if(search_list){
            search_list.childNodes.forEach((li) => {
            li.firstChild.setAttribute('target', '_blank');
            li.firstChild.setAttribute("rel", "noopener noreferrer");            
          })
        }
      }
    }
    });
    suggestionObserver.observe(suggestion_list, config)
})
 
Here's the screenshot for your reference 
 


  • Author
  • January 4, 2024

Hi Christine, thank you so much for your response. This works great! Thank you so much! :)