Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery and PhoneGap - Include a HTML file clientside with HTML or JS?

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?

like image 500
OrangeTux Avatar asked Jan 25 '12 13:01

OrangeTux


People also ask

Can I include HTML in a JavaScript file?

You can add JavaScript code in an HTML document by employing the dedicated HTML tag <script> that wraps around JavaScript code. The <script> tag can be placed in the <head> section of your HTML or in the <body> section, depending on when you want the JavaScript to load.


1 Answers

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.

like image 149
jhoff Avatar answered Sep 23 '22 04:09

jhoff