as in Javascript is not loaded into dom in jquery mobile

user3283104

I have a page1.html that has a link in it like this:

<a href="page2.html">PAGE2</a>

A part page2.html is like this:

<html>
<head>
</head>
<body>
<div data-role="page">
</div>
<script src="file1.js"></script>
<script src="file.js"></script>
</body>
</html>

And also this:

<html>
<head>
</head>
<body>
<div data-role="page">
</div>
<div data-role="page">
<script src="file1.js"></script>
<script src="file.js"></script>
</div>
</body>
</html>

These two js files implement some functionality on page2.html, but when navigating to page2.html via page1.html these two files wont work, but when done with data-ajax="false" it works. What is wrong. Where should the scripts be placed? I need default ajax for smoother transitions.

Omar

Update

As per your updated question, you can't mix Single Page Model with Multi-Page Model. When you load page2.html first data-role="page and ONLY first one is loaded. Anything else is neglected.

Example:

index.html (first page loaded) - All tags within <html> are loaded into DOM whether Ajax is enabled or disabled.

<html>
  <head>
    <!-- JS, CSS, etc.. -->
  </head>
  <body>
    <!-- pages -->
  </body>
</html>

page2.html - All tags are neglected except for FIRST data-role="page" and its' content, when Ajax is enabled.

<!-- libraries in head are neglected -->
<head>
  <!-- JS, CSS, etc.. -->
</head>
<body>

<!-- ONLY first page is loaded -->
  <div data-role="page">
   <!-- JS -->
  </div>
<!-- next pages are neglected -->
  <div data-role="page">
  </div>
</body>

When using Single Page Model and Ajax is enabled, you have to place JS libraries/code for the external page inside <div data-role="page">.

<div data-role="page">
  <script src="file1.js"></script>
  <script src="file.js"></script>
</div>

jQuery Mobile loads external pages via Ajax, it loads ONLY first <div data-role="page"> in <body and neglects any other tags out side page div.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to execute the same javascript function on each page loaded with jquery mobile

JQuery Mobile: dynamically loaded page source still available in DOM even after changing the page

jQuery Mobile DOM Page Reuse

Get the loaded page in jQuery Mobile 1.4.2

Javascript: match using dom loaded page

PHP Dynamically Loaded Data Not Recognised In DOM / By JavaScript

Javascript/jQuery not working on mobile

jQuery or Javascript check if image loaded

Checking if jquery is loaded using Javascript

Only jquery 3.2.1 or jquery mobile 1.4.5 is being loaded, why?

Remove HTML from dom if mobile browser with jQuery

How to modify a jQuery Mobile page before it's loaded?

Javascript and Jquery mobile add class

How to run Jquery after DOM is loaded in Angular Js

How to remove html added with jquery after DOM is loaded?

prevent original DOM state from being loaded with jquery function

use jQuery to find images loaded to the dom after page load?

How to execute javascript after DOM is loaded in cycle.js

How to scroll to a position after the DOM is loaded using JavaScript?

If I link external javascript, does it run after the dom is fully loaded?

Capturing an error in a Javascript subfile loaded through dom manipulation

Run JavaScript when Angular controller has loaded DOM

How to get Javascript to run after a video has fully loaded in the DOM

Append div multiple times using JavaScript on DOM Loaded

Images loaded JavaScript - Using jQuery Masonry

jquery or javascript function after all images loaded

javascript/jquery - recognize loaded from cache

Reload image after it has loaded (jquery/javascript)

JavaScript in HTML loaded using jQuery not executed