I have a site that works fine when loaded directly (f.e. by calling its URL), however, when I get to the site through a slider transition:
<li><a href="html/mySite.html" data-transition="slide">mySite</a></li>
it seems as if it would not load a .js file which is just declared within head as:
<script type="text/javascript" src="../../myJS.js"></script>
I am new to jQuery mobile, and jQuery, and HTML5, and JS. So... can someone explain to me what is the difference between a URL call and a jQuery mobile transtition regarding to the loading of the page?
(btw. I am using it to develop an Android-App)
I have a site that works fine when loaded directly (f.e. by calling its URL), however, when I get to the site through a slider transition:
<li><a href="html/mySite.html" data-transition="slide">mySite</a></li>
it seems as if it would not load a .js file which is just declared within head as:
<script type="text/javascript" src="../../myJS.js"></script>
I am new to jQuery mobile, and jQuery, and HTML5, and JS. So... can someone explain to me what is the difference between a URL call and a jQuery mobile transtition regarding to the loading of the page?
(btw. I am using it to develop an Android-App)
Share Improve this question asked Mar 15, 2013 at 11:12 Daniel KlöckDaniel Klöck 21.2k10 gold badges97 silver badges157 bronze badges1 Answer
Reset to default 6In case of multiple HTML
files, HEAD
is only loaded in the first HTML
file. In other files, only a BODY
content is loaded. This is because AJAX
is used to load other pages into the DOM
. Because there's already a HEAD
content inside an original DOM
only a body will be loaded from the other pages.
This can be prevented if you turn AJAX
loading pletely, or if you initialize all of your js fils inside a first HTML
file.
If you want to find out more take a look at my other ANSWER with several other solutions, or find it HERE.
Example 1: Correct way
HTML 1 :
<!DOCTYPE html>
<html>
<head>
<title>jQM Complex Demo</title>
<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./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>
$(document).on('pagebeforeshow', '#index', function(){
alert('Page One');
});
$(document).on('pagebeforeshow', '#second', function(){
alert('Page Two');
});
</script>
<script src="http://code.jquery./mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>
<body>
<div data-role="page" id="index">
<div data-theme="a" data-role="header">
<h3>
First Page
</h3>
<a href="second.html" class="ui-btn-right">Next</a>
</div>
<div data-role="content">
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
</div>
</div>
</body>
</html>
HTML 2 :
<div data-role="page" id="second">
<div data-theme="a" data-role="header">
<h3>
Second Page
</h3>
<a href="index.html" class="ui-btn-left">Back</a>
</div>
<div data-role="content">
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
</div>
</div>
Example 2: Incorrect way
HTML 1 :
<!DOCTYPE html>
<html>
<head>
<title>jQM Complex Demo</title>
<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./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>
$(document).on('pagebeforeshow', '#index', function(){
alert('Page One');
});
</script>
<script src="http://code.jquery./mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>
<body>
<div data-role="page" id="index">
<div data-theme="a" data-role="header">
<h3>
First Page
</h3>
<a href="second.html" class="ui-btn-right">Next</a>
</div>
<div data-role="content">
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
</div>
</div>
</body>
</html>
HTML 2 :
<!DOCTYPE html>
<html>
<head>
<title>jQM Complex Demo</title>
<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./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>
$(document).on('pagebeforeshow', '#second', function(){
alert('Page Two');
});
</script>
<script src="http://code.jquery./mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>
<body>
<div data-role="page" id="second">
<div data-theme="a" data-role="header">
<h3>
Second Page
</h3>
<a href="index.html" class="ui-btn-left">Back</a>
</div>
<div data-role="content">
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
</div>
</div>
</body>
</html>