Custom JavaScript in Document360 lets you add your own JavaScript code to extend the functionality of your knowledge base site beyond what the built-in settings provide. You paste code directly into the portal and it runs on every page of your knowledge base site. This is the right tool when you need to add dynamic behavior, interact with page elements, integrate third-party scripts, or automate interactions that cannot be configured through the standard settings.
When to use custom JavaScript
Use custom JavaScript when you need behavior or functionality that CSS and the built-in settings cannot provide:
- Modify page structure dynamically - reorder, show, or hide elements on the page based on conditions. For example, move the related articles section above the feedback section, or hide the left navigation bar for specific readers.
- Add header interactivity - append social media icons, dynamic feedback links, or custom buttons to the navigation header using JavaScript.
- Integrate third-party tools - embed analytics scripts, chat widgets, feedback tools, or custom tracking that need to run on every page.
- Show only the active category in the left sidebar - filter the category tree so only the currently active category and its sub-categories are visible, reducing navigation clutter for readers.
Before you begin
- You must have a user account with admin-level access to the Knowledge base portal.
- Custom JavaScript applies globally to the entire knowledge base site - it runs on every page and affects all readers.
- Document360 does not validate or lint your JavaScript code.
- Errors will not be flagged automatically and broken scripts can disrupt the site experience. Test your changes carefully before saving.
Document360's knowledge base site uses a Single Page Application (SPA) model. This means only the article content refreshes when a reader navigates - not the full page. Custom JavaScript that relies on page-load or page-refresh events may not work as expected. Use the articleload event instead:
panel.addEventListener('articleload', function() {
// Your custom JavaScript code here
});
Note that the articleload event fires when a reader navigates between articles. If your script targets the home page — for example, by injecting styles into the Multicolumn card section or modifying other home page elements — also test the behavior after a reader navigates away from the home page and returns to it via site navigation such as the logo, breadcrumbs, or the Home link. Scripts that execute only on the initial page load will not re-run on this type of in-app navigation. Ensure your implementation handles home page navigation the same way it handles article navigation.
How to add custom JavaScript
- Navigate to Settings () > Knowledge base site in the left navigation bar of the Knowledge base portal.
- In the left navigation pane, navigate to Site customization.

- Click Custom CSS & JavaScript.
- Select the JavaScript tab. The JavaScript code editor appears.
- Paste your JavaScript code in the text area.
- Click Save to apply your changes.

The JavaScript is now active on your knowledge base site. Visit the site to verify the behavior.
How to find and replace in the JavaScript editor
Use the Find bar at the top of the JavaScript editor to find function names, selectors, variables, or any other text in your custom JavaScript, and replace it. This is useful when you need to update a value that appears in several places, such as a CSS selector or a URL.
Find text
- Navigate to Settings () > Knowledge base site > Site customization > Custom CSS & JavaScript.
- Select the JavaScript tab.
- Click the Find field, or click inside the code editor and press Ctrl + F (Cmd + F on Mac).
- Enter the text you want to find. All matches are highlighted in the editor, and the match count appears next to the field (for example, 1 of 4).
- Press Enter or click the Next match () icon to go to the next match. Press Shift + Enter or click the Previous match () icon to go to the previous match.
- (Optional) Refine the search:
- Click Match case (
Aa) to find only matches with the same capitalization. By default, the search ignores case. - Click Use regular expression (
.*) to search with a regular expression pattern.
- Click Match case (
If no text matches, No results appears next to the field.
Replace text
- Find the text you want to replace, as described above.
- Enter the new text in the Replace field.
- Choose how to replace:
- Click Replace or press Enter in the Replace field to replace the current match and move to the next one.
- Click Replace all to replace every match at once.
- Click Save to apply your changes.

Replacements are not applied to your knowledge base site until you click Save. To undo a replacement, click inside the code editor and press Ctrl + Z (Cmd + Z on Mac). A single undo reverses an entire Replace all. To discard all unsaved changes, click Cancel.
For more details, see Custom CSS.
Use case examples
The following examples show common customizations you can achieve with custom JavaScript.
Move related articles above the feedback section
panel.onload = function () {
$(".content_block_text").append("<div class=\"sperator\"><hr></div>");
$('.related-articles-container').appendTo('.content_block_text')
}
Show only the active category in the left sidebar
/* Left sidebar category start */
let parent_data = null;
function client_tree_data(data) {
parent_data = data;
window.clientData = data;
const slug = window.location.pathname.split('/').filter(Boolean).pop();
if (slug === "docs") {
return [data[0]];
}
return data.filter(item => markIfContainsSlug(item, slug));
}
function markIfContainsSlug(node, slug) {
if (node.slug === slug) {
node.found = true;
return true;
}
return node.children?.some(child => markIfContainsSlug(child, slug)) || false;
}
/* Left sidebar category end */
Translate UI text based on reader language
Some UI text, such as the placeholder in the left navigation "Explore articles" filter, does not have a dedicated localization variable. You can use custom JavaScript to detect the reader's language from the URL and override that text.
Because some UI elements can load or re-render after the initial page load (see the Single Page Application note above), check periodically rather than only once, so the update is reliably applied.
$(document).ready(function () {
var translatedText = "Filtrera efter namn"; // replace with your translated text
var targetLangCode = "sv"; // the language code this text applies to
var lastLang = null;
function getLangFromUrl() {
var parts = location.pathname.split("/").filter(Boolean).slice(0, 3);
for (var i = 0; i < parts.length; i++) {
if (/^[a-z]{2}(-[a-z]{2,4})?$/i.test(parts[i])) {
return parts[i].toLowerCase();
}
}
return "";
}
setInterval(function () {
var lang = getLangFromUrl();
var useTranslation = (lang === targetLangCode);
if (lang !== lastLang) {
lastLang = lang;
}
$("input.filter-input").each(function () {
var $el = $(this);
if (!$el.data("orig")) {
$el.data("orig", { p: $el.attr("placeholder"), a: $el.attr("aria-label") });
}
var orig = $el.data("orig");
var p = useTranslation ? translatedText : orig.p;
var a = useTranslation ? translatedText : orig.a;
if ($el.attr("placeholder") !== p) {
$el.attr({ placeholder: p, "aria-label": a });
}
});
}, 300);
});
Replace input.filter-input with the selector for the field you want to translate, and repeat the pattern for additional languages.
For more JavaScript use case examples, see the Tips & Tricks articles.
Add a mobile-only SMS or phone CTA button
If you need a click-to-text or click-to-call button on your Help Center, use Custom JavaScript to add a floating button that appears only when the page is loaded on a mobile device. Desktop browsers do not have a default messaging or phone app, so the button is hidden on desktop automatically.
The example below adds a fixed-position button that opens the device messaging app when tapped. Replace the sms: value with your number, and adjust the label text and styling as required.
/* Mobile SMS CTA button — hidden on desktop */
(function () {
var isMobile = /Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
if (!isMobile) return;
if (document.getElementById('sms-cta-btn')) return;
var btn = document.createElement('a');
btn.id = 'sms-cta-btn';
btn.href = 'sms:+10000000000'; // replace with your SMS number
btn.textContent = 'Text us'; // replace with your preferred label
btn.style.cssText =
'position:fixed;bottom:16px;right:16px;z-index:9999;' +
'background:#0a66c2;color:#fff;padding:12px 16px;border-radius:24px;' +
'font-weight:bold;text-decoration:none;box-shadow:0 2px 8px rgba(0,0,0,.3);';
document.body.appendChild(btn);
})();
To use a click-to-call button instead, replace the href value with tel:+10000000000.
The sms: and tel: URI schemes are not supported natively in the Document360 link editor - entering them directly in the External link URL field causes a browser error. Use this Custom JavaScript approach instead for mobile devices.
Custom JavaScript does not appear in shareable preview links. To verify the button, open the live knowledge base site on a mobile device or use your browser's mobile device emulation. Changes can take up to 30 minutes to appear on public sites due to caching.
Customize the unavailable translation banner per language
When an article has not been published in the reader’s selected language, the knowledge base site displays a banner such as “This content is currently unavailable in German. You are viewing the default (English) version.” This message is not available as a localization variable and always appears in the default language.
You can use Custom JavaScript to replace this message with language-specific text. The script detects the active language from the reader’s URL path, matches it against a translations object, and replaces the banner text while preserving the icon element.
Example:
(function () {
const translations = {
en: 'This content is currently unavailable in English. You are viewing the default (English) version.',
de: 'Dieser Inhalt ist derzeit auf Deutsch nicht verfügbar. Sie sehen die Standardversion (Englisch).',
fr: 'Ce contenu est actuellement indisponible en français. Vous consultez la version par défaut (anglais).',
'pt-br': 'Este conteúdo não está disponível no momento em português (Brasil). Você está visualizando a versão padrão (inglês).',
es: 'Este contenido no está disponible actualmente en español. Estás viendo la versión predeterminada (inglés).'
};
function updateDeprecatedMessage() {
const pathSegments = window.location.pathname
.split('/')
.filter(Boolean)
.map(slug => slug.toLowerCase());
const languageSlug = pathSegments.find(slug =>
Object.prototype.hasOwnProperty.call(translations, slug)
);
if (!languageSlug) return;
const customText = translations[languageSlug];
document.querySelectorAll('.deprecated-message').forEach(element => {
const icon = element.querySelector('i');
const existingText = Array.from(element.childNodes)
.filter(node => node.nodeType === Node.TEXT_NODE)
.map(node => node.textContent)
.join('')
.trim();
if (
element.dataset.customLanguage === languageSlug &&
existingText === customText
) {
return;
}
if (icon) {
element.replaceChildren(
icon,
document.createTextNode(' ' + customText)
);
} else {
element.textContent = customText;
}
element.dataset.customLanguage = languageSlug;
});
}
updateDeprecatedMessage();
const observer = new MutationObserver(updateDeprecatedMessage);
observer.observe(document.body, {
childList: true,
subtree: true
});
window.addEventListener('popstate', updateDeprecatedMessage);
})();
The translations object maps each language URL slug (en, de, fr, pt-br, es) to your preferred replacement text. Add or remove entries to match the languages in your project, and update the text strings as required.
The .deprecated-message selector targets the banner element. The script uses replaceChildren() to replace the banner text while keeping the existing icon intact, preventing duplicate or residual text from appearing.
Because Document360 uses a Single Page Application (SPA) model, a MutationObserver monitors DOM changes and reapplies the replacement when needed. A popstate listener also handles browser back and forward navigation.
This script applies a single global replacement across all pages. It does not change which language version of an article is displayed. It only changes the text of the banner that appears when an article is unavailable in the reader’s selected language.
Show a homepage button only to signed-out readers
If your knowledge base uses authentication, you can add a Login button to the Hero section of your homepage that shows only when the reader is not signed in and hides automatically once they sign in.
What the script does:
- Hides the top-right header Login button permanently
- Shows the hero Login button while the reader is logged out
- Hides the hero Login button once the reader signs in
The script detects authentication state by checking whether the header still contains a Login button - present when logged out, replaced by profile and
sign-out options when logged in. A MutationObserver monitors the page continuously so the update applies without a page reload (required because Document360 uses a Single Page Application model).
Before adding the script, configure the Hero section button:
- Navigate to Settings ()
Knowledge base site > Site customization > Customize
site.
- Select Home from the left dropdown.
- Expand the Hero section and select Buttons.
- Click Add button, set the name to Login, and enter your login URL
in the URL field. - Click Save and Publish.
Then navigate to Custom CSS & JavaScript, select the JavaScript tab,
paste the script below, and click Save.
/* Login button: hide top-right Login, hide hero Login after sign-in */
(function () {
function isLoginText(el) {
return el.textContent.trim().toLowerCase() === "login";
}
function update() {
// Header Login buttons (desktop, tablet, mobile headers)
var headerLogins = Array.from(
document.querySelectorAll("d360-header-profile .nav-profile button")
).filter(isLoginText);
// Hide the top-right Login button
headerLogins.forEach(function (b) {
b.style.display = "none";
});
// Hero Login button: link/button in the hero that points to /login or
// says "Login"
var heroLogins = Array.from(
document.querySelectorAll("site-hero-section a, site-hero-section button")
).filter(function (el) {
var href = el.getAttribute("href") || "";
return href.indexOf("/login") !== -1 || isLoginText(el);
});
// Show it only while logged out (header still has a Login button)
heroLogins.forEach(function (el) {
if (headerLogins.length) {
el.style.removeProperty("display");
} else {
el.style.setProperty("display", "none", "important");
}
});
}
new MutationObserver(update).observe(document.documentElement, {
childList: true,
subtree: true,
});
update();
})();
Click Save.
The header check identifies the Login button by matching the word "login" in the button text. If a reader uses a browser-based page translation feature such as Google Translate, the button text is translated and the check may no longer match. This can cause the hero Login button to disappear for logged-out readers who have translated the page, or the top-right Login button to reappear. This behaviour is controlled by the reader's browser and is not configurable from Document360.
Best practices
- *Use practarticleload
event for SPA compatibility** - wrap all JavaScript that interacts with article content insidepanel.addEventListener('articleload', function() { ... })` to ensure it fires reliably on every article navigation, not just the initial page load. - ***Keep scripts focused and minimal - custom JavaScript runs on every page. Bloated or slow scripts increase page load time for all readers. Only include what is necessary.
Test in both light and dark mode - scripts that manipulate DOM elements or styles may behave differently across themes. Always preview both before saving. - Comment your code - add inline comments explaining what each block does, especially if multiple team members manage the JavaScript. Example:
/* Moves related articles above feedback — added June 2026 */ - Remove unused scripts - scripts that are no longer needed should be deleted from the editor. Leftover code increases complexity and can cause unexpected conflicts with future changes.
- Custom JavaScript does not appear in shareable preview links - to verify the final behavior, publish your changes and view the live knowledge base site directly.
FAQ
Why doesn't my custom JavaScript work after a reader navigates to a new article?
Document360 uses a Single Page Application (SPA) model — when a reader navigates between articles, only the article content refreshes, not the full page. JavaScript that relies on page-load or page-refresh events will only run once on the initial load. Wrap your code in panel.addEventListener('articleload', function() { ... }) to ensure it runs every time article content changes.
Why doesn't custom JavaScript appear in the shareable preview link?
Custom JavaScript is intentionally disabled in shareable preview links to ensure consistent performance and security when content is shared externally. To verify your JavaScript changes, publish the article and access it directly from the knowledge base site, or use a sandbox environment.
Can I add different JavaScript for each workspace?
No. Custom JavaScript is configured at the project level and applies across all workspaces within the project. It is not possible to add separate JavaScript for individual workspaces through the Custom CSS & JavaScript settings.
Why doesn't my custom JavaScript work on the home page after a reader navigates back to it?
Document360 uses a Single Page Application (SPA) model. When a reader navigates away from the home page and returns to it via site navigation - such as clicking the logo, a breadcrumb, or the Home link - the page does not perform a full reload. If your JavaScript is designed to run only on the initial page load, it will not re-execute when the reader returns to the home page this way. To ensure your home page script runs reliably after such navigation, verify that it uses an event listener or observer pattern that responds to in-app navigation and not just the initial page load. This is especially relevant for scripts that inject CSS or modify the layout of the Multicolumn card section or other home page elements.