Arun Paarthi
Arun Paarthi

Reputation: 643

Dynamic inclusion of cordova.js file is not working in Windows Phone 7?

I am developing a phone gap application for which I am supporting Android, BlackBerry, iphone and Windows Phone 7. The internet connectivity check is not working in windows phone 7 alone. There are separate cordova.js file for each platform so I am keeping these files in different folders with corresponding name like android, iphone, etc. I am dynamically loading the js file based on the type of device the application is getting loaded, say if the application is running in Android I am loading android/cordova.js. It is working fine in all platforms except for Windows Phone. If I load the js file directly in the head tag, the connectivity check is working in windows phone 7 where as loading the js file dynamically is not working. I will give the code snippet below (file path is correct I have checked it)

<script type="text/javascript" charset="utf-8">
function test() {
    $('head').append('<script type="text/javascript" src="' + filePath + '"' + '></' + 'script>');
}
test();
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady(){                               
    offLineModeTest();
}           
function offLineModeTest(){
    try {
        var networkState = navigator.network.connection.type;
        if (Connection.NONE == networkState || Connection.UNKNOWN == networkState) {
            //do something......
        }
    }catch(err){

    }
}
</script>

Upvotes: 2

Views: 2988

Answers (2)

codemonkey
codemonkey

Reputation: 5267

The recommendation for Cordova is to always load it directly in the HEAD tag and to have it as the first script that you load. If you don't do this you run the risk of events not firing correctly since it need to hook in to certain load events itself.

Why not structure your projects so that you can load a platform-specific JS file statically using relative paths rather than doing it dynamically? That is the approach I am using for my Android and iOS apps.

EDIT

This answer shows the file structure and relative inclusion of the JS file.

Upvotes: 1

Matt Lacey
Matt Lacey

Reputation: 65586

This is due to the way that javascript is not executed when loaded in this fashion in IEMobile.

No fix for this but wait for an OS update or until Cordova has all versions using the same js file.

As an alternative could you try always including hte WP7 version and then remove it and laod the appropriate one on the other platforms.

Upvotes: 1

Related Questions