0

Following this stackoverflow example off launching the Twitter app from within a phonegap app..

I thought this link below would work but its not so im guessing im lot launching the function correctly?

<a onclick="twitterCheck()">Launch Twitter App</a>

JS in the example:

//Twitter checker

// If Mac//

var twitterCheck = function(){

appAvailability.check('twitter://', function(availability) {
    // availability is either true or false
    if(availability) { window.open('twitter://user?screen_name=xerxesnoble', '_system', 'location=no');}
    else{window.open('https://itunes.apple.com/ca/app/twitter/id333903271?mt=8', '_system', 'location=no'); };
});
};

//If Android

var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");

if(isAndroid) {

    twitterCheck = function(){    

        appAvailability.check('com.twitter.android', function(availability) {
            // availability is either true or false
            if(availability) {window.open('twitter://user?screen_name=xerxesnoble', '_system', 'location=no');}
            else{window.open('https://play.google.com/store/apps/details?id=com.twitter.android', '_system', 'location=no');};
        });
    };
};
Community
  • 1
  • 1
MarkL
  • 109
  • 1
  • 14
  • possible duplicate of [JavaScript function in href vs. onclick](http://stackoverflow.com/questions/1070760/javascript-function-in-href-vs-onclick) – Liglo App Dec 02 '14 at 10:32
  • I took a look at that answer but still cant work it out - I know how to launch the fuction but the JS example I posted doesnt look like a function im used to - not sure what var twitterCheck = function(){ means? Or how to launch it? – MarkL Dec 02 '14 at 10:51

1 Answers1

1

Please take a look at this article http://javascript.info/tutorial/functions-declarations-and-expressions. I think what you are confused about the way how the function has been declared.

The way how to call this function is exactly as you tried - functionName(). If it doesn't work, it must have another reasons.

Liglo App
  • 3,719
  • 4
  • 30
  • 54