I'm creating a Jquery Mobile page and I want to repeat its header in all pages.
So I decided to do it via Jquery, where you can see below.
a) this is the header content:
var header_content = '' +
'<div data-role="controlgroup" data-type="horizontal" data-mini="true" class="ui-btn-left header-controlgroup">' +
'<a href="inicial.html" data-role="button" data-iconpos="notext" data-icon="home" id="icon-home"></a>' +
'<a href="#" data-role="button" data-iconpos="notext" data-icon="like-facebook" id="icon-like-facebook"></a>' +
'</div>' +
'<div data-role="controlgroup" data-type="horizontal" data-mini="true" class="ui-btn-right header-controlgroup">' +
'<a href="#" onclick="location.reload();" data-role="button" data-icon="refresh" data-iconpos="notext" data-inline="true" id="icon-reload"></a>' +
'<a href="#painel_config" data-rel="popup" data-role="button" data-icon="gear" data-iconpos="notext" data-inline="true" id="icon-config"></a>' +
'</div>' +
'<img src="img/logo.png" alt="image" style="display:block; margin-left:auto; margin-right:auto; height:40px; padding: 3px" />';
b) this is the HTML header that all pages have:
<!-- Header -->
<div data-role="header" data-position="fixed" class="header ui-fixed-hidden">
<div id="header-content"></div>
</div>
c) every page has a pagecreate function to add the header:
$(document).on('pagecreate', '#page_categorias', function(e) {
$('#header-content').empty();
$('#header-content').html(header_content);
});
d) all pages have these JS links:
<script src="js/jquery-1.9.0.js"></script>
<script src="js/codiqa.ext.js"></script>
<script src="js/jquery.mobile-1.3.1.min.js"></script>
e) in codiga.ext.js there are the declaration of header_content variable and pagecreation function.
EDITED: The problem is that every time I enter in the same page, the header content is duplicated, and not refresh - it's appending the header content and not refreshing it.
Where is the issue? I'm doing it in the right way?
Thanks in advance.
Try this -