4e43dcc38ee3eee9567be955d05c07b98b3c62de
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.0.1pre / docs / pages / phonegap.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 - Phonegap</title>
7         <link rel="stylesheet"  href="../../css/themes/default/" />
8         <link rel="stylesheet" href="../_assets/css/jqm-docs.css"/>
9         <script src="../../js/jquery.js"></script>
10         <script src="../../experiments/themeswitcher/jquery.mobile.themeswitcher.js"></script>
11         <script src="../_assets/js/jqm-docs.js"></script>
12         <script src="../../js/"></script>
13 </head>
14 <body>
15
16         <div data-role="page" class="type-interior">
17
18                 <div data-role="header" data-theme="f">
19                 <h1>Dynamically Injecting Pages</h1>
20                 <a href="../../" data-icon="home" data-iconpos="notext" data-direction="reverse" class="ui-btn-right jqm-home">Home</a>
21         </div><!-- /header -->
22
23         <div data-role="content">
24                 <div class="content-primary">
25                         
26                 
27                         <h2>Building PhoneGap apps with jQuery Mobile</h2>
28                         
29                         <p><a href="http://phonegap.com/" rel="external">PhoneGap</a> is an HTML5 app platform that allows developers to author native applications with web technologies and get access to APIs and app stores. Applications are built as normal HTML pages and packaged up to run as a native application within a UIWebView or WebView (a chromeless browser, referred to hereafter as a webview). Since PhoneGap is frequently used in conjunction with jQuery Mobile, we wanted to offer a few tips and recommendations to help you get staretd. </p>
30
31                         <p>The initial application document is loaded by the PhoneGap application by a local file:// URL. This means that if you want to pull in pages from your company's remote server (phone home) you will have to refer to them with absolute URLs to your server. Because your document originates from a file:// URL, loading pages or assets from your remote server is considered a cross-domain request that can be blocked in certain scenarios. </p>
32                         
33                         <p>Your ability to access cross-domain pages from within a Phone Gap jQuery Mobile application is controlled by two key things: <code>$.support.cors</code> and <code>$.mobile.allowCrossDomainPages</code>, and can also be influenced by the white list feature in later builds of PhoneGap.</p>
34
35                         <h2>$.support.cors</h2>
36
37                         <p>In jQuery core, there is a <a href="http://api.jquery.com/jQuery.support/" rel="external">$.support.cors</a> boolean that indicates whether or not jQuery thinks the browser supports the W3C "<a hre="http://www.w3.org/TR/cors/" rel="external">Cross-Origin Resource Sharing</a>" feature to support cross-domain requests.</p>
38
39                         <p>Since jQuery Mobile relies on jQuery core's $.ajax() functionality, <code>$.support.cors</code> must be set to <code>true</code> to tell <code>$.ajax</code> to load cross-domain pages. We've heard reports that webviews on some platforms, like BlackBerry, support cross-domain loading, but that jQuery core incorrectly sets <code>$.support.cors</code> value to <code>false</code> which disables cross-domain $.ajax() requests and will cause the page or assets to fail to load. </p>
40
41                         <h2>$.mobile.allowCrossDomainPages</h2>
42
43                         <p>When jQuery Mobile attempts to load an external page, the request runs through <code>$.mobile.loadPage()</code>. This will only allow cross-domain requests if the <code>$.mobile.allowCrossDomainPages</code> configuration option is set to <code>true</code>. 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 <code>$.mobile.allowCrossDomainPages</code> is set to <code>false</code>.</p>
44
45                         <p>So in PhoneGap apps that must "phone home" by loading assets off a remote server, both the <code>$.support.cors</code> AND <code>$.mobile.allowCrossDomainPages</code> must be set to <code>true</code>.  The  <code>$.mobile.allowCrossDomainPages</code> option must be set before any cross-domain request is made so we recommend wrapping this in a <code>mobileinit</code> handler:</p>
46
47 <pre><code>$( document ).bind( "mobileinit", function() {
48     // Make your jQuery Mobile framework configuration changes here!
49
50     $.mobile.allowCrossDomainPages = true;
51 });</code></pre>
52
53                         <h2>PhoneGap White Listing</h2>
54
55                         <p>PhoneGap 1.0 introduced the idea of white-listing servers that its internal webview is allowed to make cross-domain requests to. You can find info about it here on the <a href="http://wiki.phonegap.com/w/page/40796976/Install%20the%20latest%20%28trunk%29%20source%20of%20iOS%20PhoneGap">PhoneGap wiki</a>:</p>
56
57                         <p>However, not all platforms support this white-listing feature so check the PhoneGap documentation for details. Older versions of PhoneGap prior to 1.0 defaulted to allowing cross-domain requests to any server.</p>
58
59                         <h2>Still having issues?</h2>
60
61                         <p>Here are a few more tips that aren't specifically related to PhoneGap but are good to know:</p>
62
63                         <p><strong>We recommend disabling the <a href="../api/globalconfig.html">pushState feature</a> for installed apps </strong>because there are edge cases where this feature can cause unexpected navigation behavior and since URLs aren't visible in a webview, it's not worth keeping this active in these situations. </p>
64
65                         <p><strong>Android enforces a timeout when loading URLs in a webview</strong> which may be too short for your needs. You can change this timeout by editing a Java class generated by the Eclipse plugin for Android:</p>
66
67                         <code>super.setIntegerProperty("loadUrlTimeoutValue", 60000);</code>
68                         
69                         
70                         
71       </div>
72                 <!--/content-primary -->
73
74                                 <div class="content-secondary">
75
76                                         <div data-role="collapsible" data-collapsed="true" data-theme="b" data-content-theme="d">
77
78                                                         <h3>More in this section</h3>
79
80                                                         <ul data-role="listview" data-theme="c" data-dividertheme="d">
81                                                                 <li data-role="list-divider">Pages &amp; Dialogs</li>
82                                                                 <li><a href="page-anatomy.html">Anatomy of a page</a></li>
83                                                                 <li><a href="page-template.html" data-ajax="false">Single page template</a></li>
84                                                                 <li><a href="multipage-template.html" data-ajax="false">Multi-page template</a></li>
85                                                                 <li><a href="page-titles.html">Page titles</a></li>
86                                                                 <li><a href="page-links.html">Linking pages</a></li>
87                                                                 <li><a href="page-transitions.html" data-ajax="false">Page transitions</a></li>
88                                                                 <li><a href="page-dialogs.html">Dialogs</a></li>
89                                                                 <li><a href="page-cache.html">Prefetching &amp; caching pages</a></li>
90                                                                 <li><a href="page-navmodel.html">Ajax, hashes &amp; history</a></li>
91                                                                 <li><a href="page-dynamic.html">Dynamically injecting pages</a></li>
92                                                                 <li><a href="page-scripting.html">Scripting pages</a></li>
93                                                                 <li data-theme="a"><a href="phonegap.html">PhoneGap apps</a></li>
94                                                                 <li><a href="touchoverflow.html">touchOverflow feature</a></li>
95                                                                 <li><a href="pages-themes.html">Theming pages</a></li>
96                                                         </ul>
97                                         </div>
98                                 </div>
99
100                         </div><!-- /content -->
101
102                         <div data-role="footer" class="footer-docs" data-theme="c">
103                                         <p>&copy; 2011 The jQuery Project</p>
104                         </div>
105
106                         </div><!-- /page -->
107
108                         </body>
109                         </html>