
MobiLoud Back Button
A back button in a native app allows users to navigate to the previously viewed screen or page within the app. It's essential for user experience, providing a quick and intuitive way to backtrack through a series of actions or views. Without a back button, users might feel disoriented or frustrated trying to navigate within the app.
This library provides a web based widget that replicates the native look and feel provided by the iOS and Android SDKs. The purpose is to add navigation options to a web app when running in a native app container, like what MobiLoud provides.
Here's an example:

Features
ML Back Button features:
- Configuration options:
- Button text/label
- Button colors
- Position and animation
- Display options: when user scrolls screen, on page load
- Basic style settings, extensible with CSS
- Options to replace elements and attach button to a container
- Regex / url filtering, to avoid displaying the button in certain pages
- deviceData method available: its a function that can be called to get the current browser OS, useful for triggering external functions'. It returns a string containing "android" | "ios" | "windows"
- Default options set (if not texts, images or colors provided, it shows placeholder info, useful for catching errors or for testing while implementing the Button)
- Button can be used as a module or used directly in an html / script tag
- Code written in Typescript and minified/bundled with Vite
📖 How to use
ml-back-button can be used importing the JS code via CDN or as a module using NPM
🚀 With CDN
<script type="module" src="https://cdn.jsdelivr.net/npm/ml-back-button/dist/ml-back-button.min.js"></script>
<script>
function addBackButton() {
new BackButton().init();
}
window.addEventListener('load', addBackButton);
</script>
Configuration options:
const options = {
textColor: string,
fillColor: string,
buttonColorPrimary: string,
label: string,
position: 'top-right' | 'top-left' | 'bottom-left' | 'bottom-right',
animation: 'fadeIn' | 'scaleUp' | 'slideBottom' | 'slideTop' | 'slideLeft' | 'slideRight' | null,
display: 'onLoad' | 'onScrollDown' | 'onScrollUp',
radius: string,
width: string,
padding: string,
delay: number,
containerSelector: string | null,
containerOrder: 'first' | 'last' | null,
textAlign: 'center' | 'start' | 'end',
shadow: boolean,
replaceElement: string | null,
regex: string | null,
logs: boolean
}
const BackButton = new BackButton(options);
Methods
deviceData.os
deviceData.isCanvas
deviceData.isMobile
Recipes
This are useful ways to implement the widget. We always recommend using an Event Listener to trigger the code when the document is loaded window.addEventListener('load', fnName)
Insert Back Button - desktop only
function addBackButton() {
if(deviceData.isMobile || deviceData.isCanvas ){
return
}
new BackButton(options).init();
}
window.addEventListener('load', addBackButton);
Using deviceData method to filter devices
const options = {
}
if(deviceData.isCanvas) {
const backButton = new BackButton(options);
}
if(deviceData.os === "android" || deviceData.os === "windows") {
const backButton = new BackButton(options1);
}
if(deviceData.os === "desktop" || deviceData.os === "ios") {
const backButton = new BackButton(options2);
}
if(deviceData.isMobile) {
const backButton = new BackButton(options3);
}
Development
npm run build produces a production version into /dist folder
npm run dev runs dev version and starts a dev server
Testing the Back Button
You will definitely want to test the Back Button once you deploy them to your website, to make sure that everything works and looks as you want.
Running these tests on real mobile devices can get overwhelming, so we recommend that you run your tests on your desktop browser.
To do this, you will need to emulate a mobile device by adjusting your browser’s user agent. We recommend using the following Chrome extension to do this: User Agent Switcher and Manager
Once you have installed the extension, set it up as follows:
Step 1
Select “Chrome” as the browser and “Android” as the platform if you want to test the Android version of the Button, or “Safari” and “iOS” in case you want to test the iOS version:
.png?table=block&id=7b5f225a-60e2-4001-bcdb-e4627b300be4&spaceId=f1cb51a8-e748-4832-9335-2c96a2e81d09&width=1230&userId=&cache=v2)
Step 2
Select one of the options that will appear, any will work:
.png?table=block&id=dd116c73-51a6-449f-b34c-03358baadb92&spaceId=f1cb51a8-e748-4832-9335-2c96a2e81d09&width=1230&userId=&cache=v2)
Step 3
Click “Apply” to make sure the user agent is properly set up on your browser:
.png?table=block&id=eae2261a-b36c-43b3-b151-2c02fc4ac39a&spaceId=f1cb51a8-e748-4832-9335-2c96a2e81d09&width=1230&userId=&cache=v2)
Step 4
You can now press “F5” while viewing your website to refresh the browser window with the updated user agent.
Reset
If you want to revert the changes to the user agent, as some websites might start behaving differently after doing so, you can click the “Reset” button:
.png?table=block&id=9e9c3806-30d7-495e-820c-bfca7d0e8331&spaceId=f1cb51a8-e748-4832-9335-2c96a2e81d09&width=1230&userId=&cache=v2)
License
Copyright (c) MobiLoud