Configuring Defaults

Home Search

Working with jQuery Mobile's Auto-initialization

Unlike other jQuery projects, such as jQuery and jQuery UI, jQuery Mobile automatically applies many markup enhancements as soon as it loads (long before document.ready event fires). These enhancements are applied based on jQuery Mobile's default configuration, which is designed to work with common scenarios, but may or may not match your particular needs. Fortunately, these settings are easy to configure.

The mobileinit event

When the jQuery Mobile starts to execute, it triggers a mobileinit event on the document object, to which you can bind to apply overrides to jQuery Mobile's defaults.

$(document).bind("mobileinit", function(){
  //apply overrides here

Because the mobileinit event is triggered immediately upon execution, you'll need to bind your event handler before jQuery Mobile is loaded. Thus, we recommend linking to your JavaScript files in the following order:

<script src="jquery.js"></script>
<script src="custom-scripting.js"></script>
<script src="jquery-mobile.js"></script>

Within this event binding, you can configure defaults either by extending the $.mobile object using jQuery's $.extend method:

$(document).bind("mobileinit", function(){
  $.extend(  $.mobile , {
    foo: bar

...or by setting them individually:

$(document).bind("mobileinit", function(){
  $ = bar;

To quickly preview these global configuration options in action, check out the config test pages.

Configurable options

The following defaults are configurable via the $.mobile object:

activeBtnClass string, default: "ui-btn-active"
The class used for "active" button state, from CSS framework.
activePageClass string, default: "ui-page-active"
The class assigned to page currently in view, and during transitions
ajaxEnabled boolean, default: true
jQuery Mobile will automatically handle link clicks and form submissions through Ajax, when possible. If false, url hash listening will be disabled as well, and urls will load as regular http requests.
allowCrossDomainPages boolean, default: false
When jQuery Mobile attempts to load an external page, the request runs through $.mobile.loadPage(). This will only allow cross-domain requests if $.mobile.allowCrossDomainPages is set to true. Because the jQuery Mobile framework tracks what page is being viewed within the browser's location hash, it is possible for a cross-site scripting (XSS) attack to occur if the XSS code in question can manipulate the hash and set it to a cross-domain URL of its choice. This is the main reason that the default setting for $.mobile.allowCrossDomainPages is set to false. In PhoneGap apps that must "phone home" by loading assets off a remote server, both the $.support.cors AND $.mobile.allowCrossDomainPages must be set to true.
autoInitializePage boolean, default: true
When the DOM is ready, the framework should automatically call $.mobile.initializePage. If false, page will not initialize, and will be visually hidden until $.mobile.initializePage is manually called.
defaultDialogTransition string, default: 'pop'
Set the default transition for dialog changes that use Ajax. Set to 'none' for no transitions by default.
defaultPageTransition string, default: 'slide'
Set the default transition for page changes that use Ajax. Set to 'none' for no transitions by default.
gradeA function that returns a boolean, default: a function returning the value of $.support.mediaquery
Any support conditions that must be met in order to proceed.
hashListeningEnabled boolean, default: true
jQuery Mobile will automatically listen and handle changes to the location.hash. Disabling this will prevent jQuery Mobile from handling hash changes, which allows you to handle them yourself, or simply to use simple deep-links within a document that scroll to a particular ID.
ignoreContentEnabled boolean, default: false
Warning: Setting this property to true will cause performance degredation on enhancement. Once set, all automatic enhancements made by the framework to each enhanceable element of the user's markup will first check for a data-enhance=false parent node. If one is found the markup will be ignored. This setting and the accompanying data attribute provide a mechanism through which users can prevent enhancement over large sections of markup.
linkBindingEnabled boolean, default: true
jQuery Mobile will automatically bind the clicks on anchor tags in your document. Setting this options to false will prevent all anchor click handling including the addition of active button state and alternate link bluring. This should only be used when attempting to delegate the click management to another library or custom code.
loadingMessage string, default: "loading"
Set the text that appears when a page is loading. If set to false, the message will not appear at all.
loadingMessageTextVisible string, default: false
Should the text be visible when loading message is shown. (note: currently, the text is always visible for loading errors)
loadingMessageTheme string, default: "a"
Set the theme that the loading message box uses, when text is visible.
minScrollBack string, default: 250
Minimum scroll distance that will be remembered when returning to a page.
ns string, default: ""
The namespace used in data- attributes, for example, data-role. Can be set to anything, including a blank string which is the default. When using, it's clearest if you include a trailing dash, such as "mynamespace-" which maps to data-mynamespace-foo="...".

NOTE: if you're using data- namespacing, you'll need to manually update/override one selector in the theme CSS. The following data selectors should incorporate the namespace you're using:

.ui-mobile [data-mynamespace-role=page], .ui-mobile [data-mynamespace-role=dialog], .ui-page { ...

pageLoadErrorMessage string, default: "Error Loading Page"
Set the text that appears when a page fails to load through Ajax.
pageLoadErrorMessageTheme string, default: "e"
Set the theme that the error message box uses.
pushStateEnabled boolean, default: true
Enhancement to use history.replaceState in supported browsers, to convert the hash-based Ajax URL into the full document path. Note that we recommend disabling this feature if Ajax is disabled or if extensive use of external links are used.
subPageUrlKey string, default: "ui-page"
The url parameter used for referencing widget-generated sub-pages (such as those generated by nested listviews). Translates to to example.html&ui-page=subpageIdentifier. The hash segment before &ui-page= is used by the framework for making an Ajax request to the URL where the sub-page exists.
touchOverflowEnabled boolean, default: false
Enable smoother page transitions and true fixed toolbars in devices that support both the overflow: and overflow-scrolling: touch; CSS properties.