jQuery mobile not loading new page scripts

蹲街弑〆低调 提交于 2019-12-01 06:40:40

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

There are a couple of options you can choose from on how to fix this:

  1. You can put your page-specific JS inside the data-role="page" element, so it will be loaded when jQuery Mobile loads the page via AJAX.
  2. You can put all of your code in a single JS file and include it in every page on the site, it will only be loaded on full-page refreshes but this way all the code for your site will be available all the time (after minification and compression you really have to have a lot of code to make this inefficient).

I'm sure there are other methods as well but here are a couple I've had work for me.

If you just have one or two pages that require the JS to load this is what I did. Any links on your site that link to that page should be forced to 'load' the new page.

Add this to the link

rel="external"

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

target="_parent"

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!