0

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?

1
  • What is the error you get in logs? Commented Mar 2, 2012 at 5:46

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

I did that but still unable to call an external function :(
1

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
);

5 Comments

not really. just "Success : \r\n" should work too. It works when I put it in the index.html file inside the script tag.
i am calling it in onDeviceReady()
super strange. what order are you loading your js file? before or after your phonegap js?
what do you mean load? i specify <script type="text/javascript" charset="utf-8" src="phonegap-1.3.0.js"></script> before my own file
thats exactly what I mean, very strange. Sometimes the order in which you have your scripts loaded in will effect them, but you're doing it right. I am not entirely sure... do you get any errors?
0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.