简体   繁体   中英

Alert doesn't fire on Windows Phone 7 emulator using JavaScript and PhoneGap

I've tried to fire an alert on document.ready in a JavaScript file but the alert didn't fire when testing on Windows Phone 7 emulator. btw I uses PhoneGap 2.2.0, JS, and HTML here is my code

$(document).ready(function () {       
    alert("Hello World WP7");
    initPlateImage();
});

also I've tried

window.alert = navigator.notification.alert;

and

navigator.notification.alert("Hi");

but no use, Any suggestions Thanks!

Probably Cordova is not initialized at the time you call alert(). Try the following way - "deviceready" is an Cordova specific event telling you that Cordova is successfully initialized

    document.addEventListener("deviceready",onDeviceReady,false);

    function onDeviceReady()
    {
    // IE does NOT provide an alert method, you can patch it with this line after deviceready.
    window.alert = window.alert || navigator.notification.alert;

    alert("Hello World WP7");


    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM