JQuery mobile does not load new page scripts

Using jQuery Mobile with Django: While navigating to pages, the underlying scripts seem to load fine, but when moving from one page to another, new page scripts under the heading do not load in the browser.

More specific:

  • I load my homepage by entering the url and it works.
  • Download the next page by clicking on the link on the home page, and the DOM will load, but do not download the scripts associated with the page in the page header.
  • If I refresh this page, or I type the URL of this page in the browser directly (bypassing page transitions), the page loads the scripts as they should.

I know jquery mobile is trying to implement page transitions with ajax, but I hope I can save the scripts in the header and footer. I would really like to put scripts under <div data-role="page" >

+4
source share
3 answers

This is because jQuery Mobile only loads the code inside the first data-role="page" element in the DOM.

There are several options on which you can choose how to fix it:

  • You can put your JS code for the page in the data-role="page" element, so it will be loaded when jQuery Mobile loads the page via AJAX.
  • You can put all your code in one JS file and include it on every page on the site, it will be downloaded only for full-page updates, but this way all the code for your site will be available all the time (after minimizing and compressing you really need to have a lot of code to make it ineffective).

I'm sure there are other methods, but here is a couple in which I worked for me.

+12
source

If you only have one or two pages requiring JS loading, this is what I did. Any links on your site that link to this page must be forcefully uploaded to a new page.

Add this to the link

 rel="external" 
+5
source

I tried adding this to the link and it worked for me

 target="_parent" 

When I added this to my link (I still have rel = "external", though), it helped, and another page loaded with all the scripts :)

+3
source

Source: https://habr.com/ru/post/1398090/


All Articles