I am developing a jQuery Mobile Website. I am using the Multi-Page structure , that means that i have all my pages in a single html file.
I have a SERIOUS problem on loading my javascripts correctly. It literally drives me crazy , as i cant understand what/why is happening.
I have a page which has a navbar with 2 horizontal buttons on it that lead to 2 different pages. Both pages , will load the facebook javascript API and dynamically show us photos from 2 different facebook pages.
My question :
Where should i put the javascript files , that call the facebook API , of every different page that i have??
If i put the javascripts in the head of my html page , NOTHING WILL EVER load.
I try to call the javascript in the end of the content div of every page.
It looks like that:
$('#xxx').on("pageshow", function() { ... }
For the 1st page that i have , the javascript will load just fine and show me the pictures.
However the 2nd one when i navigate there through the navbar , it doesnt load the javascript. It will ONLY load it IF i press refresh on this particular page.
So what i am asking for is where and how do i put my javascripts so that they execute EVERY TIME a page has loaded?
My code looks like this:
<div data-role="page" id="photosNJ" data-theme="a" data-add-back-btn="true" data-back-btn-text="Back">
<div data-role="header" data-id="fixedNav" data-position="fixed">
<h1>Application Title</h1>
<a href="#" data-icon="back" data-rel="back" title="Go back">Back</a>
<div data-role="navbar">
<ul>
<li><a href="#photosNJ" class="ui-btn-active ui-state-persist">Photos Noche Joven</a></li>
<li><a href="#photosEJ">Photos Espacio Joven</a></li>
<li><a href="#videos">Videos</a></li>
</ul>
</div> <!-- /navbar -->
</div> <!-- /header -->
<div data-role="content">
<ul data-role="listview" data-inset="true" class="albums">
<!-- Here the albums are created through javascript (createAlbums.js) -->
</ul>
<button type="button" id="loadMoreAlbums">More Albums...</button>
<script type='text/javascript' src='javascript/createFbAlbums.js'></script>
</div> <!-- /content -->
<!-- <div id="fb-root"></div> -->
</div>
<div data-role="page" id="photosEJ" data-theme="a" data-add-back-btn="true" data-back-btn-text="Back">
<div data-role="header" data-id="fixedNav" data-position="fixed">
<h1>Application Title</h1>
<a href="#" data-icon="back" data-rel="back" title="Go back">Back</a>
<div data-role="navbar">
<ul>
<li><a href="#photosNJ">Photos Noche Joven</a></li>
<li><a href="#photosEJ" class="ui-btn-active ui-state-persist">Photos Espacio Joven</a></li>
<li><a href="#videos">Videos</a></li>
</ul>
</div> <!-- /navbar -->
</div> <!-- /header -->
<div data-role="content">
<ul data-role="listview" data-inset="true" class="albums2">
<!-- Here the albums are created through javascript (createAlbums.js) -->
</ul>
<button type="button" id="loadMoreAlbums2">More Albums...</button>
<script type='text/javascript' src='javascript/createFbAlbums2.js'></script>
</div> <!-- /content -->
<!-- <div id="fb-root"></div> -->
</div>
The javascript files all start like this :
$('#xxx').on("pageshow", function() { ... }
createFbAlbums.jsandcreateFbAlbum2.jsfiles actually look like? I assume that's where you're loading the jQMobile library?<bodytag. Own javascript files & code are best to be put right before closing the</body>, because then the rest of the page is already loaded.