0

i'm a phonegap newbie i would like to have some kind of "Header" that will load all my css and js, instead of using multiple calls in all my files.

i tried using this function

function appendScript(pathToScript) {
    var head = document.getElementsByTagName("head")[0];
    var js = document.createElement("script");
    js.type = "text/javascript";
    js.src = pathToScript;
    head.appendChild(js);
}

but that don't seem to work

is there any other method to call multiple js files? please note that jQuery is not loaded

1 Answer 1

1

No! I tried similar script, it only works for css, but not for js.

By the way, do you mean that you have many html files? Cuz I'm using Single Page Approach, I have only ONE html file, i.e. the index.html.

And I put everything inside div, for example, if you have a.html and b.html, I have index.html with 2 div block,

namely

<div id="a" hidden="false"> and <div id="b" hidden="true">

the above is similar to a user opens the a.html.

When user click b.html, I make 'b' visible and 'a' invisible.

For many pages design, how can you handle the 'deviceready' issue? You have to wait the ondeviceready for each page before any api can be used!

Sign up to request clarification or add additional context in comments.

6 Comments

thanks Kenneth. well, using one page approach is nice when you have small app, but i need about 50 screens so it's almost impossible to work on this kind of one-page.
Actually I have more than 100 screens. the id from div001 to div1xx. if using multiple pages, I need to wait for deviceready for each page, since I'm also using signalr for my chat application, the connection is lost evertime I change from page a to page b.
if you read tutorial from the internet, it is also advised that we should use single page approach in most cases.
by the way, my app was Actually using multi-pages at the beginning, I found it too difficult to maintain the vars and states between pages and I convert it to single page aroundw 3 months ago
I give you an example. as we are using mobile phone, which means that connection will be lost or may be slow at Any time. suppose a user use page a to read that from the server, the connection is very slow at the time being, so we may use async connection to read server data, during the time, may be say, 10 seconds, the user don't want to wait anymore and already move to page b and looking at something else, after another 5 seconds, the data from the Server comes back! Now, how can you update content in page a when the user already move to page b?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.