Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6373525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:22:30+00:00 2026-05-25T01:22:30+00:00

I am developing an iphone app on phonegap and I am using jQuery mobile.

  • 0

I am developing an iphone app on phonegap and I am using jQuery mobile. I want to implement a simple functionality on a page like when press a button on my html page, check if I have internet connection. If I do, then proceed on the next page else, display the error page.

I include the libraries:

<link rel="stylesheet" type="text/css" href="lib/jquery.mobile-1.0b1.min.css" />
    <script type="text/javascript" src="lib/jquery-1.6.1.js"></script>  
    <script type="text/javascript" charset="utf-8" src="phonegap.0.9.5.1.min.js"></script>
    <script type="text/javascript" src="functionality.js"></script>
    <script type="text/javascript" src="lib/jquery.mobile-1.0b1.min.js"></script> 

my html code of page1.html is:

<a href = "#map_page" id='map_button' data-role="button" onclick = "connection();">Go!</a>

Now the functionality.js file contains the connection() function which is written according to the phonegap’s docs:

function connection(){
alert('checking...');
// check if there is internet connection
navigator.network.isReachable("google.com", isNetworkAvailable, {});

}

function isNetworkAvailable(status) {
     var networkState = status.code;
     alert('Connection Type ' + networkState + ' - ' + status.message); }

The problem is that I am never getting in the connection() function, not even when I use the following script in my html page:

$(‘#map_button’).click (function(event) {
checkConnection()});

I’ve been working on this piece of code for a few days without being able to make it work. I would really appreciate your help…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:22:31+00:00Added an answer on May 25, 2026 at 1:22 am

    I was also having trouble getting checking for a connection but found an alternative method of doing it using var networkState = navigator.network.connection.type; I’ve implemented it quite differently binding a switched function to all my links. As it maybe on interest in the deviceReady method I bind all links to call a function that will decide whether or that link needs connection checking or not. Skip to second function for connection stuff!

     function onDeviceReady()
    {
    
        //Bind all links and intercept them before they go anywhere //I'm jquery dependant 
        $('a').bind('click', function(event) {
            switch($(this).attr('id'))//using the id value of the link we help us decide what kidn of action we are doing
            {
                case "data-loader-page":
                    return event;
                break;
    
                case "load-version-data": //I'm about to pull JSON data from a server
    
                    if(!checkConnection()){return false}; //check for connection and exit if it fails.
    
                    doJSON(); //at this point we have a connection so go get remote data.
                    return false;
                break;
    
                //for un-handled links we will assume that you just want to hash bang
                default: return event;
            }
        }); 
    }
    

    This function works just fine for me and you can call it inline on your onclick event if you want. It doesn’t depend on jquery either.

    function checkConnection() {
        var networkState = navigator.network.connection.type;
    
        var states = {};
        states[Connection.UNKNOWN]  = 'Unknown connection';
        states[Connection.ETHERNET] = 'Ethernet connection';
        states[Connection.WIFI]     = 'WiFi connection';
        states[Connection.CELL_2G]  = 'Cell 2G connection';
        states[Connection.CELL_3G]  = 'Cell 3G connection';
        states[Connection.CELL_4G]  = 'Cell 4G connection';
        states[Connection.NONE]     = 'No network connection';
    
        if(states[networkState]==states[Connection.NONE] || states[networkState]==states[Connection.UNKNOWN]){
            alert('A network connection is required to access this page.');
            return false;
        } else {
            return true;    
        }
    }
    

    I’m jquery / jquery mobile dependant

    <div data-role="page" data-theme="b" id="sql-manager-page">
        <div data-role="header">
            <h1>SQL Manager</h1>
        </div>
        <div data-role="content">
            <ul data-role="listview">
                <li><a href="#data-loader-page" id="data-loader-page">Data Loader</a></li>
                    <li><a href="#load-version-data" id="load-version-data" rel="external">Load version data</a></li>
            </ul>
    
    
        </div>
        <div data-role="footer">
            <h4> <a href="#privacy-page">Privacy</a></h4>
        </div>
    </div>
    

    Not the most elegant example I know but I hope this helps;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.