Reputation: 69
I have a shared div footer that all his interior elements have to be the same for both pages.
<div id="page1" data-role="page">
</div>
<div id="page2" data-role="page">
</div>
<div id="bar" data-role="footer" class="sharedSlideBar">
</div>
Later on I will change the page1 using $.mobile.navigate('#page2') and I wan't to keep the functionality and the styles of the pages to the shared div footer (#bar) How is it possible?
Upvotes: 0
Views: 86
Reputation: 11496
jQuery mobile have two page templates.
One have every page placed inside a single HTML file, like in your case. It is also called multipage template.
Second one have 1 page per 1 HTML file. And it is called multi-HTML template.
Read more about them here.
What you need is a multi-HTML template. Here a working example:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="widdiv=device-widdiv, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<title>
</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://www.dragan-gaic.info/js/jquery-1.8.2.min.js">
</script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script>
$(document).on('pagebeforeshow', "#index",function () {
$(document).on('click', "#changePage",function () {
$.mobile.changePage('second.html', { dataUrl : "second.html?paremeter=123", data : { 'paremeter' : '123' }, reloadPage : false, changeHash : true });
});
});
$(document).on('pagebeforeshow', "#second",function () {
var parameters = $(this).data("url").split("?")[1];;
parameter = parameters.replace("parameter=","");
alert(parameter);
});
</script>
</head>
<body>
<!-- Home -->
<div data-role="page" id="index">
<div data-role="header">
<h3>
First Page
</h3>
</div>
<div data-role="content">
<a data-role="button" id="changePage">Javascript change page example</a>
<a href="second.html" data-transition="slide">Direct link button</a>
</div> <!--content-->
</div><!--page-->
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="widdiv=device-widdiv, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<title>
</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://www.dragan-gaic.info/js/jquery-1.8.2.min.js">
</script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>
<body>
<!-- Home -->
<div data-role="page" id="second">
<div data-role="header">
<h3>
Second Page
</h3>
</div>
<div data-role="content">
</div> <!--content-->
</div><!--page-->
</body>
</html>
There's one more thing you need to know. Only first HTML file can have more then one inner data-role="page"
. Every other HTML page can have ONLY 1 data-role="page"
inside. Reason for this is described here. If you need more information just give me a comment.
Upvotes: 1