mwl undefined in some files, but not others
I'm having a problem getting MWL to work - in some files in my project, it works just fine, but in others it doesn't. This happens even if the code is identical - I can copy and paste the entire contents of one file into another, and it will work in the first but not the second. When I check the type of MWL ( using alert( typeof mwl ); or alert( typeof window.mwl); ), it comes up as undefined in some files and as object in others - again, even if the code in the 2 files is identical.
I can't find any project settings or anything else that would cause this, and it only seems to be happening in certain files - in others, MWL is defined and the functions work just fine.
Any help with this would be greatly appreciated.
Thanks.
Re: mwl undefined in some files, but not others
Hi and welcome to forum!
Could you describe, those situations where you encounter this problem, in more detail?
Is it just simulator (local / cloud preview) or after deploying to device?
Br,
Ilkka
Re: mwl undefined in some files, but not others
It's in the both the local and cloud preview simulators. Additionally, I discovered after posting that it seems to be only when there is something in the query string - when I have something in the query string, the <body> section of the page (or maybe the entire page, tough to tell) seems to load twice; the first time MWL seems to load properly, but the second it doesn't. With no query string, everything seems to load normally. I've confirmed that it's none of my scripts doing this, as it still happens when the scripts are removed entirely.
I'm testing this by putting the following at the start of the <body> section:
<script language="javascript" type="text/javascript">
alert( typeof mwl );
</script>
When there is no query string, the alert box pops up once, with the text 'object' (as expected). With a query string, it appears twice, once with 'object', and then again with 'undefined'.
Re: mwl undefined in some files, but not others
Also, this only seems to happen the first time - everything works fine until the first time you call a page with a query string, but after that, the pages only load once and MWL is always undefined whether there is a query string or not, until restarting the app.
Re: mwl undefined in some files, but not others
Thanks for the clarification, but now I'm even more confused :)
Are you having multiple pages, and for example, link to those pages using query strings to pass data, or what is the use case for query strings?
Br,
Ilkka
Re: mwl undefined in some files, but not others
Yeah, multiple pages. So, for example, index.html will have a link, testpage.html?test=1, and clicking on that link will cause the problems. Simply loading testpage.html without a query string works fine.
In this specific case I'm using the query strings to pass information categories between pages.
Re: mwl undefined in some files, but not others
Hi,
Ok that explains. MWL library is dynamically injected to main HTML page (usually index.html), but it is not designed to be injected in other pages.
Ideally there should be only one HTML page, in Series 40 Web Apps. Other pages, or to be precise content from other pages, should be inserted to main HTML page in DIV containers.
Please read more from Best Practices document. See section 5.1 Multi-page web apps
[url]http://tools.nokia.com/wt/doc/jsdt/s40/Series_40_Web_Apps_Best_Practices_Guide.pdf[/url]
Br,
Ilkka
Re: mwl undefined in some files, but not others
Is there any way to do page reloads and still have MWL work, then? My app deals with large amounts of data and it would be impossible to have it all loaded at the same time, so it needs to be done dynamically as needed, so even if it's just index.html being reloaded with different variables it's just not practical for me to keep a single page loaded constantly.
In any case, thanks for your help.
Re: mwl undefined in some files, but not others
Ok I think I've found an alternate solution which should work.
Thanks for the info!
Re: mwl undefined in some files, but not others
Page reloads are not really supported in web Apps. Good to know that you found an alternative way :)
Please don't hesitate to ask if you encounter any further problems.
Ps. And as a last tip: always use device to test if something works or not. Simulator is not 100% accurate match to actual device.
Br,
Ilkka
Re: mwl undefined in some files, but not others
Funny you should mention deploying to device, because I'm having trouble with it :)
I'm using the short url deployment method as I don't currently have bluetooth on my computer, but in the ovi browser on my phone (Nokia C1-01) there doesn't seem to be any way to actually enter the URL. I tried downloading the latest Nokia Browser but apparently it isn't compatible with the phone, so I'm not entirely sure what to do. Any suggestions would be appreciated!
Re: mwl undefined in some files, but not others
I'm really sorry to say, but Nokia C1-01 is not in the list of supported models for Series 40 Web Apps.
Currently supported models:
200 200.* 2000 2000.* 201 201.* 2010 2010.* 202 202.* 203 203.* 2700* 2730* 300 300.* 3000 3000.* 302 302.* 303 303.* 3030 3030.* 3710* 5130* 5330* 6303* 6600* 6700* 7230* c2-01* c2-02* c2-03* c2-05* c2-06* c2-07* c2-08* c3-00* c3-01* x2-00* x2-01* x2-02* x2-05* x3-00* x3-02*
[url]http://download.browser.ovi.com/[/url]
Br,
Ilkka
Re: mwl undefined in some files, but not others
That certainly explains a few things. Time to get a new device!
Thanks for all your help :)