I'm using jQuery Mobile and rely much on it's history state feature so I would like to use the jQuery way to redirect user to another "page". This is the latest method from their latest documentation.
p/s: The reason I prefer jQuery navigation method is because of the hashchange/history and each transition can be different instead of one global transition.
Note: jQuery.mobile.changePage is deprecated as of jQuery Mobile 1.4.0 and will be removed in 1.5.0. Use the pagecontainer widget's change() method instead.
But I tried and it's not working. Anyone have experience on this can point me my error? Just hope to make my code up to date, so use their latest method.
The code as below:
Code update:
$.mobile.pagecontainer( "change", $('#page2'));
<!doctype html>
<html>
<head>
<title>Multipage example</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="jqm/jquery.mobile-1.4.0.min.css" />
<script src="jqm/jquery-1.11.0.min.js"></script>
<script src="jqm/jquery.mobile-1.4.0.min.js"></script>
</head>
<body>
<div data-role="page" id="page1">
<div data-role="header">
<h1>Page 1</h1>
</div>
<div role="main" class="ui-content">
<a href="#page2" data-transition="slide" class="ui-btn ui-corner-all ui-btn-inline">Go To Page 2</a>
</div>
</div>
<div data-role="page" id="page2">
<div data-role="header">
<h1>Page 2</h1>
</div>
<div role="main" class="ui-content">
<a href="#page1" data-rel="back" data-transition="slide" class="ui-btn ui-corner-all ui-btn-inline">Go Back To Page 1</a>
</div>
</div>
<script>
console.log('Next line will start redirect');
$( "#page1" ).pagecontainer( "change", $('#page2'));
</script>
</body>
</html>