Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the data-url attribute do in jquery mobile?

Trying to figure out the basic structure of a page and came across a blog that had the data-url attribute. What exactly does this mean?

like image 291
locoboy Avatar asked May 06 '11 21:05

locoboy


People also ask

What is data role in jQuery mobile?

Pages & DialogsA page in jQuery Mobile consists of an element with a data-role="page" attribute. Within the "page" container, any valid HTML markup can be used, but for typical pages in jQuery Mobile, the immediate children of a "page" are divs with data-role="header" , class="ui-content" , and data-role="footer" .

What is data URL attribute?

The data attribute specifies the URL of the resource to be used by the object.

What is data attribute in jQuery?

The data-* attribute is used to store custom data private to the page or application. The data-* attribute gives us the ability to embed custom data attributes on all HTML elements.

Why we use data attribute in HTML?

data-* attributes allow us to store extra information on standard, semantic HTML elements without other hacks such as non-standard attributes, or extra properties on DOM.


2 Answers

That attribute serves to identify pages that are auto-generated by jQM. From the jQM docs:

...Pages that are auto-generated by plugins use the following special data-url structure: <div data-url="page.html&subpageidentifier">

So, for example, a page generated by the listview plugin may have an data-url attribute like this: data-url="artists.html&ui-page=listview-1"

When a page is requested, jQuery Mobile knows to split the URL at "&ui-page" and make an HTTP request to the portion of the URL before that key. In the case of the listview example mentioned above, the URL would look like this: http://example.com/artists.html&ui-page=listview-1 ...and jQuery Mobile would request artists.html, which would then generate its sub-pages, creating the div with data-url="artists.html&ui-page=listview-1", which it will then display as the active page.

Note that the data-url attribute of the element contains the full URL path, not just the portion after &ui-page=. This allows jQuery Mobile to use a single consistent mechanism that matches URLs to page data-url attributes.

like image 100
ampersand Avatar answered Sep 22 '22 02:09

ampersand


The data-url attribute also serves to update the hash when using redirects or linking to directories. Check out the Redirects and linking to directories section.

like image 35
barry Avatar answered Sep 23 '22 02:09

barry