Phonegap (Cordova) iOS button click

Posted by JNM on Stack Overflow See other posts from Stack Overflow or by JNM
Published on 2012-10-08T18:33:48Z Indexed on 2012/10/09 3:37 UTC
Read the original article Hit count: 161

Filed under:
|
|

I am trying to create a very simple phone gap application for iOS. I am using query mobile. the problem is, that i can't get javascript event to fire on button click.
Code i have now:

<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
    <meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1">
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="js/jquery.mobile-1.2.0.css" />
    <script type="text/javascript" charset="utf-8" src="cordova-1.8.1.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/jquery.mobile-1.2.0.min.js"></script>
    <script type="text/javascript">
        document.addEventListener("deviceready", onDeviceReady, false);

        function onDeviceReady() {
        }

        function showAlert() {
            navigator.notification.alert("Cordova is working");
        }

    </script>
</head>
<body>
    <div data-role="page" id="options" data-add-back-btn="true" data-back-btn-text="Atgal">
        <div data-role="header" data-position="fixed">
            <h1>Title</h1>
        </div>
        <div data-role="content">
            <h1>Alert</h1>
            <p><a href="#" onclick="showAlert(); return false;" data-role="button">Show alert</a></p>
        </div>
    </div>
</body>
</html>

I tried multiple solutions to fix my problem, but none of them works. When have button with # in href, it doesn't event change the color on click. When i add url, it changes color. But it never call javascript function. Another problem is, that document.addEventListener("deviceready", onDeviceReady, false); works only in the index page. If i press button in initial page which redirects to another page, OnDeviceReady function is never called.
Anybody has any ideas?

© Stack Overflow or respective owner

Related posts about ios

Related posts about phonegap