Take the 2-minute tour ×

I'm creating an native Android application by using PhoneGap and jQuery Mobile.

When I create a multipaged page, i don't to include the same navigationbar all the time. So I tried to include a (s)html. But it doesn't work. This is what i've tried this far:

<!--#include file="navigation.inc.html" -->
<!--#include virtual="navigation.inc.html" -->
<!--#include file="navigation.inc.shtml" -->
<!--#include virtual="navigation.inc.shtml" -->

This page is not placed on a (web)server. When the navigation.inc.shtml is not a server, is it possible to include the file with html or javascript?

share|improve this question

3 Answers 3

up vote 1 down vote accepted

I'm running into the same issue. As far as I can tell, Android ignores Server Side Includes.

I've been getting close to the answer with load based on this answer but I'm taking a slightly different approach:

Wherever you need to include an external file:

<div data-include="footer"></div>

Then, at the end of my ( multipage ) index.html

$('div[data-include]').each(function() {
    $(this).load( $(this).attr('data-include') + '.html').trigger('create');

The problem is that it doesn't work for the initial page view. Any subsequent pages look great.

share|improve this answer
See: stackoverflow.com/questions/7974630/… –  tomo7 Apr 20 '13 at 19:54

I was looking to a write-once approach to data-role="footer"s, and got it working as shown below. What I don't like it 1.) its not from an include file so 2.) the navbar code is a bit hard to read and maintain. (This code does NOT go in document.ready.)

var myFooter = '<div data-role="navbar"><ul><li><a href="#myPageName" >Send</a></li><li><a href="#myPageTwo" >Set Up</a></li><li><a href="#myPageThree" >Help</a></li></ul></div>';

// use this code pointing to each data-role="footer" where you want this navbar
$('div#myPageName').live("pagebeforecreate", function(){

the pagecreate event works too.

share|improve this answer

I used the client side javascript code as suggested above from Jhof.

template example for Navigation header:

<body onLoad="initialization()">
  <div template-include="nav-header">
  <script type="text/javascript">
    function loadTemplates() 
  $('div[template-include]').each(function() {
      $(this).load('tpl/' + $(this).attr('template-include') + '.html').trigger('create');
    function initialization() {


I've created an initialization function where I call all my init functions as loadTemplates()

my initializationFunction is called from body.onLoad event. onLoad event fire at the end of the html parsing!

So it work also at the initial page view.

share|improve this answer

Your Answer


