I want a navigation bar on the top of my site. I use a external file for this navbar.
<div data-role="navbar">
<ul>
<li><a href="#home">Startseite</a></li>
<li><a href="#library">Bibliothek</a></li>
<li><a href="#statistics">Statistik</a></li>
</ul>
</div>
But now I want to set the class ui-btn-active
and ui-state-persist
so I know on wich page I am currently. So my question is how I do I find out on wich page I am currently so I am able to set this class. I also post here one of the pages.
<div data-role="page" id="statistics">
<div data-role="header">
<h1>Statistik</h1>
<?php
include './static/navbar.php';
?>
</div>
<div data-role="main" class="ui-content">
</div>
</div>
I am using a lamp server so I have the ability to use php.
The # param in url is a browser parameter, so php can't obtain this (I think). You must use javascript to check total url with document.URL
and post it to a php via ajax. When php recibe the data you can use this to obtain THE NEXT OF#, the anchor that you want.
$foo = parse_url('http://www.example.com/index.php#action', PHP_URL_FRAGMENT);
Car read about this here http://php.net/manual/en/function.parse-url.php
But I think that you can select the buttons only with javascript. Taking the url you can process it and take only after # and add a class to the button that match. Here are good ino to take anchor How to get the anchor from the URL using jQuery?