Reputation: 51272
How can I show the second page as the default page in a jQuery mobile Multi-page template structure?
<body>
<div data-role="page" id="foo">
<div data-role="header">
<h1>Foo</h1>
</div>
<div data-role="content">
<p>I'm first in the source order so I'm shown as the page.</p>
</div>
</div>
<div data-role="page" id="home">
<div data-role="header">
<h1>Home</h1>
</div>
<div data-role="content">
<p>I'm the second in the source order so I'm hidden when the page loads. I'm just shown if a link that references my id is beeing clicked.</p>
</div>
</div>
<div data-role="page" id="bar">
<div data-role="header">
<h1>Bar</h1>
</div>
<div data-role="content">
<p>I'm the second in the source order so I'm hidden when the page loads. I'm just shown if a link that references my id is beeing clicked.</p>
</div>
</div>
</body>
Upvotes: 8
Views: 7194
Reputation: 138
I know this question is a little old but i stumbled on a simple solution:
window.location.href = "_dash.html#page-two";
or if youre navigating from a seperate page you can make a link that drops u in the second page like so:
<a href="_dash.html#page-two">link to second page</a>
Simply add the page id for the second page at the end of your url
Upvotes: 0
Reputation: 57309
Working example: http://jsfiddle.net/Gajotres/UfDaf/
This part will prevent normal page load. Don't forget, like in my example mobileinit MUST be initialized before jQuery Mobile
is initialized.
$(document).on("mobileinit",function() {
$.mobile.autoInitializePage = false;
});
This part will start manual page initialization:
$(document).ready(function() {
window.location.hash = 'home';
$.mobile.initializePage();
});
While I usually advise against of document ready usage here we need it to kick start the manual change.
In case jsFiddle
is down.
HTML :
<!DOCTYPE html>
<html>
<head>
<title>jQM Complex Demo</title>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; target-densityDpi=device-dpi"/>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).on("mobileinit",function() {
$.mobile.autoInitializePage = false;
});
</script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
</head>
<body>
<div data-role="page" id="foo">
<div data-role="header">
<h1>Foo</h1>
</div>
<div data-role="content">
<p>I'm first in the source order so I'm shown as the page.</p>
</div>
</div>
<div data-role="page" id="home">
<div data-role="header">
<h1>Home</h1>
</div>
<div data-role="content">
<p>I'm the second in the source order so I'm hidden when the page loads. I'm just shown if a link that references my id is beeing clicked.</p>
</div>
</div>
<div data-role="page" id="bar">
<div data-role="header">
<h1>Bar</h1>
</div>
<div data-role="content">
<p>I'm the second in the source order so I'm hidden when the page loads. I'm just shown if a link that references my id is beeing clicked.</p>
</div>
</div>
</body>
</html>
Javascript :
$(document).ready(function() {
window.location.hash = 'home';
$.mobile.initializePage();
});
Upvotes: 14