2.0_beta sync to rsa
[framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.1.0 / docs / pages / page-links.html
1 <!DOCTYPE html> 
2 <html>
3         <head>
4         <meta charset="utf-8">
5         <meta name="viewport" content="width=device-width, initial-scale=1"> 
6         <title>jQuery Mobile Docs - Linking Pages</title> 
7         <link rel="stylesheet"  href="../../css/themes/default/jquery.mobile.css" />  
8         <link rel="stylesheet" href="../_assets/css/jqm-docs.css"/>
9
10         <script src="../../js/jquery.js"></script>
11         <script src="../../docs/_assets/js/jqm-docs.js"></script>
12         <script src="../../js/"></script>
13
14 </head> 
15 <body> 
16
17         <div data-role="page" class="type-interior">
18
19                 <div data-role="header" data-theme="f">
20                 <h1>Linking pages</h1>
21                 <a href="../../" data-icon="home" data-iconpos="notext" data-direction="reverse">Home</a>
22                 <a href="../nav.html" data-icon="search" data-iconpos="notext" data-rel="dialog" data-transition="fade">Search</a>
23         </div><!-- /header -->
24
25         <div data-role="content">
26                         <div class="content-primary">   
27                         <h2>Linking pages</h2>
28                         
29                         <p>jQuery Mobile is designed to work with simple page linking conventions. Essentially, you can link pages and assets as you normally would, and jQuery Mobile will automatically handle page requests in a single-page model, using Ajax when possible. When Ajax isn't possible (such as a non-same-domain url, or if specified using certain attributes on the link), a normal http request is used instead.</p> 
30
31                         <p>The goal of this model is to allow developers to create websites using best practices &mdash; where ordinary links will "just work" without any special configuration &mdash; while creating a rich, native-like experience that can't be achieved with standard HTTP requests.</p> 
32                         
33                         <h2>Default link behavior: Ajax</h2> 
34                                                         
35                         <p>To enable animated page transitions, all links that point to an external page (ex. products.html) will be loaded via Ajax. To do this unobtrusively, the framework parses the link's <code>href</code> to formulate an Ajax request (Hijax) and displays the loading spinner. All this happens automatically by jQuery Mobile.</p>
36                                 
37                         <p>If the Ajax request is successful, the new page content is added to the DOM, all mobile widgets are auto-initialized, then the new page is animated into view with a page transition.</p>
38                         
39                         <p>If the Ajax request fails, the framework will display a small error message overlay (styled in the "e" swatch) that disappears after a brief time so this doesn't break the navigation flow. View an <a href="notapage.html">example of the error message</a>.</p>
40                         
41                         <p><strong>Note:</strong> You cannot link <strong>to</strong> a multipage document with Ajax navigation active because the framework will only load the first page it finds, not the full set of internal pages. In these cases, you must link without Ajax (see next section) for a full page refresh to prevent potential hash collisions. There is currently a <a href="https://github.com/ToddThomson/jQuery-Mobile-Subpage-Widget" rel="external">subpage plugin</a> that makes it possible to load in multi-page documents.</p>
42
43
44 <h2>Linking without Ajax</h2>
45                 
46                 <p>Links that point to other domains or that have <code>rel="external"</code>, <code>data-ajax="false"</code> or <code>target</code> attributes will not be loaded with Ajax. Instead, these links will cause a full page refresh with no animated transition. Both attributes (<code>rel="external"</code> and <code>data-ajax="false"</code>) have the same effect, but a different semantic meaning: <code>rel="external"</code> should be used when linking to another site or domain, while <code>data-ajax="false"</code> is useful for simply opting a page within your domain from being loaded via Ajax. Because of security restrictions, the framework always opts links to external domains out of the Ajax behavior.</p>
47                 <p>In version 1.1, we've added support for using <code>data-ajax="false"</code> on a parent container which allows you to excluded a large number of links from the Ajax navigation system. This avoids the need to add this attribute to every link in a container.</p>
48                 <p>Note: When building a jQuery Mobile application where the Ajax navigation system is disabled globally or frequently disabled on individual links, we  recommend disabling the <code>$.mobile.pushStateEnabled</code> global <a href="../api/globalconfig.html">configuration option</a> to avoid inconsistent navigation behavior in some browsers.</p>
49                 
50
51
52                 <h2>Linking within a multi-page document</h2> 
53                 
54                         <p>A single HTML document can contain one or many 'page' containers simply by stacking multiple divs with a <code> data-role</code> of <code>"page"</code>. This allows you to build a small site or application within a single HTML document; jQuery Mobile will simply display the first 'page' it finds in the source order when the page loads.</p> 
55                         
56                         <p>If a link in a multi-page document points to an anchor (<code>#foo</code>), the framework will look for a page wrapper with that ID (<code>id="foo"</code>). If it finds a page in the HTML document, it will transition the new page into view. You can seamlessly navigate between local, internal "pages" and external pages in jQuery Mobile. Both will look the same to the end user except that external pages will display the Ajax spinner while loading. In either situation, jQuery Mobile updates the page's URL hash to enable Back button support, deep-linking and bookmarking. </p>
57                 
58                 <p>It's important to note that if you are linking from a mobile page that was loaded via Ajax to a page that contains multiple internal pages, you need to add a <code>rel="external"</code> or <code>data-ajax="false"</code> to the link. This tells the framework to do a full page reload to clear out the Ajax hash in the URL. This is critical because Ajax pages use the hash (<code>#</code>) to track the Ajax history, while multiple internal pages use the hash to indicate internal pages so there will be conflicts in the hash between these two modes.</p>
59                 
60                 <p>For example, a link to a page containing multiple internal pages would look like this:</p>
61                         
62                         <code>&lt;a href=&quot;multipage.html&quot; rel=&quot;external&quot;&gt;Multi-page link&lt;/a&gt;</code>
63
64                                 
65
66                 <h2>"Back" button links</h2>
67                 <p>If you use the attribute <code>data-rel="back"</code> on an anchor, any clicks on that anchor will mimic the back button, going back one history entry and ignoring the anchor's default <code>href</code>. This is particularly useful when generating "back" buttons with JavaScript, such as a button to close a dialog. 
68                 When using this feature in your source markup, although browsers that support this feature will not use the specified <code>href</code> attribute, <strong>be sure to still provide a meaningful value that actually points to the URL of the referring page to allow the feature to work for users in C-Grade browsers</strong>. If users can reach this page from more than one referring pages, specify a sensible <code>href</code> so that the navigation remains logical for all users. 
69                 Also, please keep in mind that if you just want a reverse transition without actually going back in history, you should use the <code>data-direction="reverse"</code> attribute instead.
70                 Note: <code>data-direction="reverse"</code> is meant to simply run the backwards version of the transition that will run on that page change, while <code>data-rel="back"</code> makes the link functionally equivalent to the browser's back button and all the standard back button logic applies. Adding <code>data-direction="reverse"</code> to a link with <code>data-rel="back"</code> <b>will not</b> reverse the reversed page transition and produce the "normal" version of the transition. 
71                 </p>
72                 
73                                 
74                 <h2>Redirects and linking to directories</h2>
75                 
76                 <p>When linking to directory indexes (such as href="typesofcats/" instead of href="typesofcats/index.html"), you must provide a trailing slash. This is because jQuery Mobile assumes the section after the last "/" character in a url is a filename, and it will remove that section when creating base urls from which future pages will be referenced.</p>
77                 
78                 <p>However, you can work around this issue by returning your page div with a <code>data-url</code> attribute already specified. When you do this, jQuery Mobile will use that attribute's value for updating the URL, instead of the url used to request that page. This also allows you to return urls that change as the result of a redirect, for example, you might post a form to "/login.html" but return a page from the url "/account" after a successful submission. This tool allows you to take control of the jQuery Mobile history stack in these situations. Here's an example:</p>
79                 
80                 <p>The following link points to "docs-links-urltest/index.html": <a href="docs-links-urltest/index.html">Test Link</a> which is a directory with an index page. The return page will update the hash as "/docs/pages/docs-links-urltest/" with a trailing slash. This is done via the data-url attribute in that page's source. Keep in mind that the value will replace the entire hash, and it is up to you to replace it with a URL that actually resolves to the correct page when requested via refresh or deep link.</p>
81                 
82                 <p>Learn more about the technical details of the navigation model and <a href="page-navmodel.html">Ajax, hashes and history</a> in jQuery mobile.</p>
83                 
84                 
85                 
86                 <h2>Link examples</h2>
87                                         <p>All standard HTML link types are supported in jQuery Mobile in addition to the types outlined above. Here is a sampler of many common link types:</p>
88                         
89                         <ul data-role="listview" data-inset="true" data-theme="d" data-divider-theme="d">
90                                 <li data-role="list-divider">Links that will be Ajax-loaded with page transitions</li>
91                                 <li><a href="../../index.html">Link in the same domain</a></li>
92                                 <li><a href="../pages/dialog.html" data-rel="dialog">Dialog link: data-rel="dialog" (not tracked in history)</a></li>
93                                 <li data-role="list-divider">Links that will refresh the page</li>
94                                 <li><a href="http://www.jquery.com">External domain</a></li>
95                                 <li><a href="../../index.html" rel="external">Link with rel="external"</a></li>
96                                 <li><a href="index.html" data-ajax="false">link with [data-ajax="false"]</a></li>
97                                 <li><a href="../../index.html" target="foo">Link with target="foo"</a></li>
98                                 <li data-role="list-divider">Email links</li>
99                                 <li><a href="mailto:jdoe@foo.com">Basic email: mailto:jdoe@foo.com</a></li>
100                                 <li><a href="mailto:jdoe@foo.com?cc=bill@bar.com&bcc=mark@abc.com&subject=Happy%20Birthday&body=Best%20wishes!">Mailto with a cc:, bcc:, subject and body pre-filled</a></li>
101
102                                 <li data-role="list-divider">Phone links</li>
103                                 <li><a href="tel:15555555555">Phone: tel:15555555555</a></li>
104                                 <li data-role="list-divider">Other</li>
105                                 <li><a href="#">A href="#" will return false</a></li>
106                         </ul>
107
108                 
109                                 </div><!--/content-primary -->          
110
111                                 <div class="content-secondary">
112
113                                         <div data-role="collapsible" data-collapsed="true" data-theme="b" data-content-theme="d">
114
115                                                         <h3>More in this section</h3>
116
117                                                         <ul data-role="listview" data-theme="c" data-dividertheme="d">
118
119                                                                 <li data-role="list-divider">Pages &amp; Dialogs</li>
120                                                                 <li><a href="page-anatomy.html">Anatomy of a page</a></li>
121                                                                 <li><a href="page-template.html" data-ajax="false">Single page template</a></li>
122                                                                 <li><a href="multipage-template.html" data-ajax="false">Multi-page template</a></li>
123                                                                 <li><a href="page-titles.html">Page titles</a></li>
124                                                                 <li data-theme="a"><a href="page-links.html">Linking pages</a></li>
125                                                                 <li><a href="page-transitions.html">Page transitions</a></li>
126                                                                 <li><a href="page-dialogs.html">Dialogs</a></li>
127                                                                 <li><a href="page-cache.html">Prefetching &amp; caching pages</a></li>
128                                                                 <li><a href="page-navmodel.html">Ajax, hashes &amp; history</a></li>
129                                                                 <li><a href="page-dynamic.html">Dynamically injecting pages</a></li>
130                                                                 <li><a href="page-scripting.html">Scripting pages</a></li>
131                                                                 <li><a href="phonegap.html">PhoneGap apps</a></li>
132                                                                 <li><a href="touchoverflow.html">touchOverflow feature</a></li>
133                                                                 <li><a href="pages-themes.html">Theming pages</a></li>
134                                                         </ul>
135                                         </div>
136                                 </div>          
137
138                         </div><!-- /content -->
139
140                         <div data-role="footer" class="footer-docs" data-theme="c">
141                                         <p>&copy; 2011-12 The jQuery Foundation</p>
142                         </div>
143
144                         </div><!-- /page -->
145
146                         </body>
147                         </html>