Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

The way JQM loads pages is by getting the element with the attribute data-role="page" via ajax, and not the whole document.

So, how do I make JQuery Mobile load the styles and scripts from any page (or a refresh), rather than only loading them in the entry point (index.htm)?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Just put them into the BODY tag.

It is described in my other answer: Why I have to put all the script to index.html in jquery mobile

share|improve this answer

Thanks, I had all my JS on one file, but the jquery, jqm, and jqm css files needed to be on each page too. What I ended up doing was including a script on each page body that checks if the scripts exist. If they were not there, they would be dynamically added.

It would be like this

    if (document.getElementsByTagName('script') < 3)
    {
     createElement
     setAttribute
     append inside head element
     //repeat for each script / styleshet
    }

    else
     //do nothing 

If I went the route of including all the files in the body, there would be a redundancy of the assets being requested on each page change. I believe this gets around it. It seems to work so far.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.