-2

I'm including the same javascript file in the head of 2 html files:

<script src="js/app.js"></script>

And html page1 then links to html page2. But when you follow the hyperlink to page2, the code in the javascript file doesnt get called again when page2 loads. And even when I try to add a block of code in the head or body of html file 2 to call a function in the JS file, it never executes.

Am I doing something wrong?

EDIT: Heres the code http://jsfiddle.net/dL6gpveL/1/

EDIT2: So everything works normally when I dont have JQuery Mobile included. Any idea why this would happen? Its version 1.4.5

EDIT3: Sorry I should have said I was using jquery mobile in the first place.

Lukesmith
  • 170
  • 2
  • 16

2 Answers2

0

Edit: I have tried reproducing your problem without any luck. I have no trouble loading the javascript file and executing functions.

My Setup:

"Folder/index.html"
"Folder/crews.html"
"Folder/js/app.js"
"Folder/js/jquery-1.11.1.min.js"

What does your browser console say when trying to load the .js files?

Edit: I noticed that you are trying to fetch "js/jquery.mobile-1.4.5.min.map" but your jquery mobile file is found at "js/jquery.mobile-1.4.5.min.js". Could that have something to do with it?

Edit: The 404 on jquery.mobile-1.4.5.min.map is probably unrelated. My bad.

But after looking at how all the pages was loaded, it puzzled me and I did some looking around.. I found this post about jquery mobile: https://stackoverflow.com/a/17406387/3209951

Try the 3 steps mentioned in the post and see if that helps.

Also check the two links in that post for more information about jquery mobile.

Community
  • 1
  • 1
dimma314
  • 21
  • 2
0

So it turns out the issue was that when you use JQuery Mobile, the stuff in the head doesnt get loaded again. Only the code in the "page" div. So you have to call the JS functions within there and it works fine.

Lukesmith
  • 170
  • 2
  • 16