Download How to configure jQuery Mobile defaults.mp4
Configuring jQuery Mobile defaults allows you to change how the framework behaves and looks globally, without having to repeat settings for every widget or element.
Here’s a complete explanation of how and where to configure jQuery Mobile defaults:
🧩 1. Use the mobileinit Event
The mobileinit event fires before jQuery Mobile is fully loaded and initialized.
You can use it to override global defaults and settings.
✅ Example:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery Mobile Defaults Example</title>
<!-- Include jQuery first -->
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<!-- Configure defaults BEFORE loading jQuery Mobile -->
<script>
$(document).on("mobileinit", function () {
// Disable AJAX navigation
$.mobile.ajaxEnabled = false;
// Change default transition
$.mobile.defaultPageTransition = "slide";
// Set a default theme
$.mobile.page.prototype.options.theme = "b";
// Disable pushState to avoid hash URLs
$.mobile.pushStateEnabled = false;
// Set loader options
$.mobile.loader.prototype.options.text = "Loading...";
$.mobile.loader.prototype.options.textVisible = true;
$.mobile.loader.prototype.options.theme = "b";
});
</script>
<!-- Now load jQuery Mobile -->
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
</head>
<body>
<div data-role="page" id="home">
<div data-role="header"><h1>Home</h1></div>
<div data-role="content">
<p>Page with custom defaults applied!</p>
</div>
</div>
</body>
</html>
⚙️ 2. Common Global Defaults You Can Configure
Here are some of the most useful options:
| Category | Option | Description |
|---|---|---|
| Navigation | $.mobile.ajaxEnabled |
Enables/disables AJAX page loading. |
| Navigation | $.mobile.linkBindingEnabled |
Enables/disables automatic link handling. |
| Navigation | $.mobile.pushStateEnabled |
Enables/disables hash-less URLs. |
| Transitions | $.mobile.defaultPageTransition |
Sets the default transition (fade, slide, flip, etc.). |
| Theme | $.mobile.page.prototype.options.theme |
Sets a default page theme (like "a", "b"). |
| Loader | $.mobile.loader.prototype.options.text |
Text shown in the loading spinner. |
| Loader | $.mobile.loader.prototype.options.textVisible |
Whether to show loader text. |
| Loader | $.mobile.loader.prototype.options.theme |
Loader theme. |
| Touch | $.mobile.touchOverflowEnabled |
Enables CSS overflow scrolling. |
⚠️ 3. Important Notes
-
The order of scripts is critical:
You must include yourmobileinithandler before loading thejquery.mobile.jsfile. -
Some defaults can only be changed at initialization time (inside
mobileinit), not afterward. -
jQuery Mobile is largely deprecated for modern projects (it’s not maintained). For new mobile UIs, frameworks like Bootstrap, Framework7, or Ionic are recommended.
Enjoy! follow us for more...

No comments:
Post a Comment