{"id":115,"date":"2011-03-07T20:14:12","date_gmt":"2011-03-07T20:14:12","guid":{"rendered":"http:\/\/www.sitekickr.com\/blog\/?p=115"},"modified":"2011-03-07T20:15:35","modified_gmt":"2011-03-07T20:15:35","slug":"custom-javascript-with-jquery-mobile","status":"publish","type":"post","link":"https:\/\/www.sitekickr.com\/blog\/custom-javascript-with-jquery-mobile\/","title":{"rendered":"Combining custom JavaScript with jQuery Mobile"},"content":{"rendered":"<p>If you&#39;ve tried integrating your own JavaScript into a jQuery Mobile site, you might find that it executes only once, on the first page the user visits.<\/p>\n<p>This is not a bug, but purely a side-effect of the way jQuery Mobile uses AJAX requests to load pages.<\/p>\n<p>By wrapping your JS as seen below, you&#39;re script will be called with each page &quot;transition&quot;:<\/p>\n<p><code>$(&#39;div&#39;).live(&#39;pageshow&#39;,function(event, ui){<br \/>\n\t&nbsp; initMySite();<br \/>\n\t}<\/code><\/p>\n<p>To ensure that your code is called on the first page, as well as all subsequent pages, you&#39;ll need to do the following:<\/p>\n<p><code>$(document).ready(function() {<br \/>\n\t&nbsp; initMySite();<br \/>\n\t&nbsp; $(&#39;div&#39;).live(&#39;pageshow&#39;,function(event, ui){<br \/>\n\t&nbsp;&nbsp;&nbsp; initMySite();<br \/>\n\t&nbsp; });<br \/>\n\t});<\/code><\/p>\n<p><code>initMySite = function() { <br \/>\n\t&nbsp; \/\/ my initialization code goes here <br \/>\n\t}<br \/>\n\t<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#39;ve tried integrating your own JavaScript into a jQuery Mobile site, you might find that it executes only once, on the first page the&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"amp_status":""},"categories":[5],"tags":[50],"_links":{"self":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/115"}],"collection":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/comments?post=115"}],"version-history":[{"count":3,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/115\/revisions"}],"predecessor-version":[{"id":118,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/115\/revisions\/118"}],"wp:attachment":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/media?parent=115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/categories?post=115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/tags?post=115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}