【问题标题】:Correct way to launch a function from a href?从href启动功能的正确方法?
【发布时间】:2014-12-12 18:34:56
【问题描述】:

this stackoverflow 为例,从 phonegap 应用程序中启动 Twitter 应用程序..

我认为下面的这个链接会起作用,但我猜我不能正确启动该功能?

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

示例中的JS:

//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');};
        });
    };
};

【问题讨论】:

  • 我看了那个答案,但仍然无法解决 - 我知道如何启动该功能,但我发布的 JS 示例看起来不像我以前使用的功能 - 不确定 var twitterCheck =函数(){是什么意思?或者如何启动它?

标签: jquery cordova


【解决方案1】:

请看这篇文章http://javascript.info/tutorial/functions-declarations-and-expressions。我认为您对函数的声明方式感到困惑。

调用这个函数的方式和你尝试的完全一样——functionName()。如果不行,那一定是另有原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-03
    • 1970-01-01
    • 2016-01-23
    • 1970-01-01
    • 2017-08-08
    • 2015-06-13
    • 2019-08-31
    相关资源
    最近更新 更多