Michael
Michael

Reputation: 91

javascript document.ready() function not working in windows phone emulator with cordova 1.5

I just created a new project using the visual studio cordova starter template. However I am unable to get the javascript document ready function to be called when running from the windows phone 7 emulator. When running from a browser it is called fine.

onDeviceReady()... gets logged to the console, but $(document).ready(...) does not.

Can anyone see any obvious reason for this?

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>

    <title>Title</title>

    <link rel="stylesheet" href="jquery.mobile-1.0.1.css"/>
    <script src="jquery-1.7.1.js"></script>
    <script src="jquery.mobile-1.0.1.js"></script>
    <script type="text/javascript" charset="utf-8" src="cordova-1.5.0.js"></script>
  </head>
  <body>
    <div id="home" data-role="page">
    </div>
    <script type="text/javascript">
        document.addEventListener("deviceready", onDeviceReady, false);

        function onDeviceReady() {
            console.log("onDeviceReady. You should see this message in Visual Studio's output window.");
        }

        $(document).ready(function () {
            console.log("doc ready");
        });
    </script>
  </body>
</html>

Upvotes: 0

Views: 3767

Answers (1)

ColinE
ColinE

Reputation: 70160

document.ready is most likely being called before the PhoneGap code has initialized the console which you are logging to. The WP7 browser does not have its own console, the console is implemented by the PhoneGap framework.

Upvotes: 2

Related Questions