Question

I am an iOS and PhoneGap newbie. I have the index.html file and a javascript file called MyClass.js.

In my MyClass.js, I have a function -

var MyClass = {

testfunc: function() {
    navigator.notification.alert("Success : \r\n");
}

}

I am trying to call it from the index.html function like -

MyClass.testfunc();

In my Phonegap.plist file I have an entry MyClass-Myclass as a key-value pair with the type String. However I don't get the alert. What am I doing wrong?

Was it helpful?

Solution

Have you included the following in your index.html:

<script src="MyClass.js"></script>

This will allow you to use the MyClass.js functions in your index.html file

OTHER TIPS

Your markup for your alert is wrong...

navigator.notification.alert(
    'Some Alert Text here', // alert message
    successCallback, // callback function
    'Alert Title, // alert title
    'OK' // button text
);

Hi can you try following code:

// MyClass.js
var MyClass = {
    testFunction: function() {
        alert("hi there");
    }
};

// index.html
<html>
<head>
</head>
<body>
    <script src="MyClass.js"></script>
    <script src="phonegap-1.3.0.js"></script>
    <script type="text/javascript">
        document.addEventListener("deviceready", function() {
            navigator.notification.alert("hi there \r\n");
            //alert("hi there \r\n");
        });
    </script>
</body>
</html>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top