// salla · javascript · free add-ons
Free JavaScript Codes for Salla: 7 Add-ons That Make Your Store Look Professional Without Paid Apps

Free JavaScript codes for Salla are the fastest way to add features that other store owners pay monthly subscriptions for: a free-shipping bar that updates with the cart, a countdown for a real offer, an exit-intent coupon popup, and a floating WhatsApp button. Each one is a single snippet you copy and paste, with no app and no subscription.
Short answer: open the JavaScript box in your theme customization inside the Salla dashboard, paste the seven JavaScript codes for Salla below (all of them or just the ones you want), change the values marked at the top of each snippet, then save and test your store on mobile and desktop.
This is part two of the series. In part one we changed how the store looks with CSS codes. Here we add behavior: things that move, update and react to the customer. It is written for Salla only, because these codes rely on Salla’s own developer tools (the Twilight SDK) and do not work on other platforms.
I tested every snippet on Salla’s official demo store with the Raed theme (Twilight SDK version 3.0.28) and checked the events and elements on screen before publishing. Below I explain exactly what I tested and what I could not.
According to Salla’s help center, editing the theme with code (CSS and JavaScript) requires the Pro or Special plan, a custom domain for your store, and the Store Design permission on your account. Check your plan because requirements can change, and see the official details on the theme code customization page.
Menu names may differ slightly as the platform updates. Before any change, copy whatever is already in the box into a text file as a backup.
Open your store, press F12, go to the Console tab and type typeof salla. If it prints object, Salla’s tools are ready and the snippets that depend on them will work. If a red error appears when the page loads, read its line: it is usually a character missed while copying.
Rules that apply to all the codes:
--color-primary variable that the theme sets.inset-inline-end, so they work in both Arabic (RTL) and English (LTR).Most shoppers in Saudi Arabia prefer to ask you a question on WhatsApp before buying. This button stays visible on every page with a ready-made message, and on mobile it lifts itself above the bottom bar so it does not cover the theme’s buttons.
Change: PHONE to your number in international format (like 9665xxxxxxxx, without + or zeros) and MSG to your message. The number in the code is a placeholder, so do not forget to replace it.
/* 1) Floating WhatsApp button */
(function () {
var PHONE = '966500000000'; // your number in international format, no + or leading zeros
var MSG = 'Hello, I have a question';
if (document.getElementById('kx-wa')) return;
var css = document.createElement('style');
css.textContent =
'#kx-wa{position:fixed;inset-inline-end:16px;z-index:9990;width:54px;height:54px;border-radius:50%;background:#25d366;display:grid;place-items:center;box-shadow:0 8px 22px rgba(0,0,0,.25);transition:transform .2s}' +
'#kx-wa:hover{transform:scale(1.08)}#kx-wa svg{width:28px;height:28px;fill:#fff}';
document.head.appendChild(css);
var a = document.createElement('a');
a.id = 'kx-wa';
a.href = 'https://wa.me/' + PHONE + '?text=' + encodeURIComponent(MSG);
a.target = '_blank';
a.rel = 'noopener';
a.setAttribute('aria-label', 'Chat with us on WhatsApp');
a.innerHTML = "<svg viewBox='0 0 24 24'><path d='M12 2a10 10 0 0 0-8.6 15.1L2 22l5-1.3A10 10 0 1 0 12 2zm0 18.2c-1.5 0-3-.4-4.2-1.2l-.3-.2-3 .8.8-2.9-.2-.3A8.2 8.2 0 1 1 12 20.2zm4.5-6.1c-.2-.1-1.5-.7-1.7-.8-.2-.1-.4-.1-.6.1l-.8 1c-.1.2-.3.2-.5.1a6.700 6.700 0 0 1-3.300-2.900c-.2-.4.2-.4.700-1.300.1-.2 0-.3 0-.5l-.8-1.800c-.2-.5-.4-.4-.6-.4h-.5c-.2 0-.5.1-.7.300-.7.700-1 1.500-.9 2.400.2 1.200.8 2.300 1.600 3.200 1.500 1.700 3.300 2.700 5.500 3.100.8.100 1.600 0 2.200-.6.400-.4.600-.9.500-1.400-.1-.2-.3-.3-.5-.4z'/></svg>";
function place() {
var bar = document.querySelector('.mobile-bottom-bar');
var h = bar ? bar.offsetHeight : 0;
a.style.bottom = (h ? h + 16 : 20) + 'px';
}
document.body.appendChild(a);
place();
window.addEventListener('resize', place);
})();A thin line in your store color fills as the visitor scrolls down the page. It gives the store an app-like, professional feel and helps on long product pages and blog posts. It needs no changes.
/* 2) Reading progress bar at the top of the page */
(function () {
if (document.getElementById('kx-progress')) return;
var bar = document.createElement('div');
bar.id = 'kx-progress';
bar.style.cssText =
'position:fixed;top:0;inset-inline-start:0;height:3px;width:0;z-index:99999;background:var(--color-primary,#0f766e);transition:width .1s linear;pointer-events:none';
document.body.appendChild(bar);
function update() {
var h = document.documentElement.scrollHeight - window.innerHeight;
bar.style.width = (h > 0 ? Math.min(100, (window.scrollY / h) * 100) : 0) + '%';
}
window.addEventListener('scroll', update, { passive: true });
update();
})();Category pages on Salla are long, and on mobile the customer gets tired of scrolling back up. The button appears after 600 pixels of scrolling and sits above the bottom bar when there is one. To change when it appears, edit the number 600.
/* 3) Back-to-top button */
(function () {
if (document.getElementById('kx-top')) return;
var css = document.createElement('style');
css.textContent =
'#kx-top{position:fixed;inset-inline-start:16px;z-index:9990;width:44px;height:44px;border:0;border-radius:50%;background:var(--color-primary,#0f766e);color:var(--color-primary-reverse,#fff);font-size:20px;line-height:1;cursor:pointer;box-shadow:0 6px 18px rgba(0,0,0,.2);opacity:0;visibility:hidden;transform:translateY(10px);transition:all .25s}' +
'#kx-top.on{opacity:1;visibility:visible;transform:none}';
document.head.appendChild(css);
var b = document.createElement('button');
b.id = 'kx-top';
b.type = 'button';
b.setAttribute('aria-label', 'Back to top');
b.textContent = '↑';
b.addEventListener('click', function () {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
document.body.appendChild(b);
function place() {
var bar = document.querySelector('.mobile-bottom-bar');
var h = bar ? bar.offsetHeight : 0;
b.style.bottom = (h ? h + 16 : 20) + 'px';
}
place();
window.addEventListener('resize', place);
window.addEventListener('scroll', function () {
b.classList.toggle('on', window.scrollY > 600);
}, { passive: true });
})();This is the strongest code on the list. It shows at the top of the page how much more the customer needs to add to get free shipping, updates instantly when a product is added, removed or its quantity changes, and hides when the cart is empty. It relies on the cart events in the Twilight SDK (I confirmed the salla.cart.event.onUpdated event fires on the store itself).
Change: THRESHOLD to your free-shipping threshold in riyals. The bar is display only: it does not apply free shipping by itself, so set the same threshold in Salla’s shipping settings so the customer is never promised something that does not happen.
/* 4) Free-shipping bar (updates with the cart) */
(function () {
var THRESHOLD = 200; // free-shipping threshold in SAR (same value as in your shipping settings)
if (document.getElementById('kx-ship')) return;
var css = document.createElement('style');
css.textContent =
'#kx-ship{display:none;padding:8px 16px;text-align:center;font-size:14px;font-weight:700;background:#f4f7f2;color:#1f2937}' +
'#kx-ship.on{display:block}' +
'#kx-ship .t{height:6px;max-width:420px;margin:6px auto 0;border-radius:99px;background:#e5e7eb;overflow:hidden}' +
'#kx-ship .t i{display:block;height:100%;width:0;border-radius:99px;background:var(--color-primary,#0f766e);transition:width .4s ease}';
document.head.appendChild(css);
var box = document.createElement('div');
box.id = 'kx-ship';
box.innerHTML = "<span class='m'></span><div class='t'><i></i></div>";
document.body.insertBefore(box, document.body.firstChild);
function render(cart) {
if (!cart || !cart.count) { box.classList.remove('on'); return; }
var total = Number(cart.total) || 0;
var left = THRESHOLD - total;
box.querySelector('.m').textContent = left > 0
? 'Add ' + Math.ceil(left) + ' SAR more and get free shipping 🚚'
: 'Congrats! Your order gets free shipping 🎉';
box.querySelector('i').style.width = Math.min(100, (total / THRESHOLD) * 100) + '%';
box.classList.add('on');
}
salla.onReady(function () {
salla.cart.event.onUpdated(render);
salla.cart.latest().then(function (r) {
render(r && r.data && r.data.cart);
});
});
})();A colored bar that counts down the days and hours until your offer ends. The countdown is tied to a fixed end date, not a fake timer that restarts for every visitor. That is deliberate: a fake timer destroys trust the moment the customer comes back and sees it restart, so it is better for the offer to be real. When time runs out, the bar removes itself.
Change: END to when your offer ends (the code uses Riyadh time, +03:00) and TEXT to the wording you want.
/* 5) Countdown for a real offer that ends on a fixed date */
(function () {
var END = new Date('2026-12-31T23:59:59+03:00'); // when your real offer ends (Riyadh time)
var TEXT = 'Offer ends in';
if (document.getElementById('kx-count') || END - Date.now() <= 0) return;
var box = document.createElement('div');
box.id = 'kx-count';
box.style.cssText =
'padding:8px 16px;text-align:center;font-weight:700;font-size:14px;background:var(--color-primary,#0f766e);color:var(--color-primary-reverse,#fff)';
document.body.insertBefore(box, document.body.firstChild);
function pad(n) { return String(n).padStart(2, '0'); }
function tick() {
var s = Math.max(0, Math.floor((END - Date.now()) / 1000));
var d = Math.floor(s / 86400), h = Math.floor((s % 86400) / 3600),
m = Math.floor((s % 3600) / 60), x = s % 60;
box.textContent = TEXT + ' ' + d + 'd : ' + pad(h) + 'h : ' + pad(m) + 'm : ' + pad(x) + 's';
if (s === 0) { clearInterval(t); box.remove(); }
}
var t = setInterval(tick, 1000);
tick();
})();When the visitor moves the mouse toward the top of the browser (a sign they are about to close the page), a popup appears with a discount code they can copy in one click. It shows at most once every 3 days per visitor so it does not annoy them, and closes with Esc or by clicking outside.
Important: this idea works on desktop only, because touch screens have no mouse pointer leaving the page, so the code ignores mobile automatically. And create the discount code first in your store discounts with the same name you put in CODE, otherwise you will show a code that does not work.
/* 6) Exit-intent coupon popup (desktop only, once every 3 days) */
(function () {
var CODE = 'WELCOME10'; // create this code in your store discounts first
var TITLE = 'Wait! Get 10% off before you go';
var DAYS = 3;
var KEY = 'kx_exit_seen';
try {
if (Date.now() - Number(localStorage.getItem(KEY) || 0) < DAYS * 864e5) return;
} catch (e) {}
if (window.matchMedia('(pointer:coarse)').matches) return; // does not run on touch screens
var shown = false;
function copyText(t) {
var fb = function () {
return new Promise(function (res, rej) {
var ta = document.createElement('textarea');
ta.value = t;
ta.setAttribute('readonly', '');
ta.style.cssText = 'position:fixed;top:0;opacity:0';
document.body.appendChild(ta);
ta.select();
var ok = false;
try { ok = document.execCommand('copy'); } catch (e) {}
ta.remove();
ok ? res() : rej();
});
};
if (navigator.clipboard && window.isSecureContext) return navigator.clipboard.writeText(t).catch(fb);
return fb();
}
function show() {
if (shown) return;
shown = true;
try { localStorage.setItem(KEY, String(Date.now())); } catch (e) {}
var o = document.createElement('div');
o.style.cssText = 'position:fixed;inset:0;z-index:100000;background:rgba(0,0,0,.55);display:grid;place-items:center;padding:16px';
o.innerHTML =
"<div role='dialog' aria-modal='true' style='background:#fff;color:#111;max-width:380px;width:100%;border-radius:16px;padding:28px 24px;text-align:center;box-shadow:0 20px 60px rgba(0,0,0,.35)'>" +
"<h3 style='margin:0 0 10px;font-size:20px'>" + TITLE + "</h3>" +
"<p style='margin:0 0 16px;color:#555'>Copy the code and use it at checkout</p>" +
"<button type='button' class='kx-copy' style='width:100%;padding:12px;border:2px dashed var(--color-primary,#0f766e);border-radius:12px;background:#f4f7f2;font-size:20px;font-weight:800;letter-spacing:2px;cursor:pointer'>" + CODE + "</button>" +
"<button type='button' class='kx-close' style='margin-top:14px;background:none;border:0;color:#777;cursor:pointer;font-size:14px'>No thanks</button></div>";
document.body.appendChild(o);
function close() { o.remove(); }
o.addEventListener('click', function (e) { if (e.target === o) close(); });
o.querySelector('.kx-close').addEventListener('click', close);
o.querySelector('.kx-copy').addEventListener('click', function () {
var btn = this;
copyText(CODE).then(function () { btn.textContent = 'Copied ✓'; }, function () {});
});
document.addEventListener('keydown', function esc(e) {
if (e.key === 'Escape') { close(); document.removeEventListener('keydown', esc); }
});
}
document.addEventListener('mouseout', function (e) {
if (e.clientY <= 0 && !e.relatedTarget) show();
});
})();A small detail that gives the customer instant confirmation the product went into the cart, especially on mobile where they may miss the notification. The icon briefly bounces, and it stops automatically for anyone who turned on Reduce Motion on their device.
/* 7) Cart icon bump when a product is added */
(function () {
var css = document.createElement('style');
css.textContent =
'@keyframes kxBump{0%{transform:scale(1)}30%{transform:scale(1.35) rotate(-8deg)}60%{transform:scale(.95)}100%{transform:scale(1)}}' +
'.kx-bump{animation:kxBump .6s ease}' +
'@media (prefers-reduced-motion:reduce){.kx-bump{animation:none}}';
document.head.appendChild(css);
salla.onReady(function () {
salla.cart.event.onItemAdded(function () {
document.querySelectorAll('.s-cart-summary-icon, .mobile-bottom-bar__item--cart').forEach(function (el) {
el.classList.remove('kx-bump');
void el.offsetWidth;
el.classList.add('kx-bump');
});
});
});
})();You should know what I verified and what I did not, because that is the difference between a tested guide and a copied one:
})(); breaks the whole snippet. Copy from the first comment to the last line.Where do I put JavaScript code in Salla?
From the dashboard open Store Design, then Customize, then the Theme customization tab, where you will find the JavaScript box. According to Salla’s help center the feature requires the Pro or Special plan, a custom domain and the Store Design permission. Requirements can change, so check your plan.
Do these codes work on Zid?
No, these JavaScript codes for Salla are written for Salla only. Some that do not rely on Salla’s tools, like the progress bar, may work on any site, but the shipping bar and cart animation depend on Salla’s Twilight SDK and I did not test them elsewhere.
Does JavaScript slow down a Salla store?
These snippets are tiny (about 10 KB combined) and run after the page loads, so the effect on speed is small. What usually slows stores down is large images and external apps.
Can a code break my store?
An error in JavaScript stops that snippet only, not the store. Still, keep a backup of what is in the box, paste one snippet at a time, and if something goes wrong delete the last snippet and save.
Does the exit popup work on mobile?
No. Exit intent is detected by the mouse moving toward the top of the browser, which does not exist on touch screens, so the code skips mobile automatically. You can compensate with a coupon in a sticky bar or one that appears after a set time.
Do I need programming experience?
No. Copying, pasting and changing the clearly marked numbers and texts at the top of each snippet, like the WhatsApp number, the free-shipping threshold and the offer date, is enough.
For a quick win, start with the free-shipping bar and the WhatsApp button: they have the clearest effect on the buying decision. Then add the rest once you are sure each one works. If you have not read part one (free CSS codes for Salla and Zid), start there so the look and the behavior come together.
Running paid ads for your store? First set up Salla conversion tracking so you know which addition actually raised your sales.
Read next: Salla Store Losing Sales? 7 Leaks That Aren’t Your Ads, and CSS Codes for the Product Page in Salla.
Want these add-ons applied and tuned to your store identity?
This is part of my Salla and Zid store design service. I implement them, match them to your brand and test on every device. Send me your store link and I will tell you honestly what is worth changing first.