phonegap应用程序没有打开链接

时间:2017-03-26 21:57:29

标签: android html5 cordova phonegap-plugins

我刚刚使用html5移动网站模板开始了我的第一个phonegap应用程序。

我部署了它,但外部链接无法在应用上运行。当我点击链接时,没有任何反应。

我在app中添加了inappbrowser和whitelist插件。

我已将此代码添加到html文件的head部分:

<script type="text/javascript">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    window.open = cordova.InAppBrowser.open;
}
</script>

以及我如何创建链接:

<a href="#" onclick="window.open('http://apache.org', '_blank',);" class="logo-css"></a>

我该怎么做才能使这项工作成功?感谢

1 个答案:

答案 0 :(得分:0)

试试这个:

class node{
public:
node() { 
    clear(); 
}
node(char z) {
    clear(); 
}
~node() {
    for (int x = 0; x < MAX_NODES; x++) {
        if (next[x]) {
            delete next[x];
        }
    }
}
void clear() {
    for (int x = 0; x < MAX_NODES; x++){
        next[x] = 0;
        isWord = false;
    }
}
bool isWord;
int count;//frq
std::vector<std::string> files;
node* next[MAX_NODES];
map<string, int> counts;
};
class index {
public:
void add(std::string s, std::string fileName) {
    std::transform(s.begin(), s.end(), s.begin(), tolower);
    std::string h;
    int freq=0;
    for (std::string::iterator i = s.begin(); i != s.end(); i++) {
        if (*i == 32) {
            pushFileName(addWord(h), fileName);
            h.clear();
            continue;
        }
        h.append(1, *i);
    }
    if (h.length()){
        pushFileName(addWord(h), fileName);
    }
}
void findWord(std::string s, map<string, int> counts) {
    std::vector<std::string> v = find(s);
    if (!v.size()) {
        std::cout <<"'"<< s + "' is not found!\n";
        return;
    }
    std::cout << "'" << s << "' is found in:\n";
    for (std::vector<std::string>::iterator i = v.begin(); i != v.end(); i++) {
        std::cout << *i << "\n";

    }
    std::cout << "frequency is : ";

}
private:
void pushFileName(node* n, std::string fn) {
    std::vector<std::string>::iterator i = std::find(n->files.begin(), n->files.end(), fn);
    if (i == n->files.end()){
        n->files.push_back(fn);
        n->count;
    }
}

const std::vector<std::string>& find(std::string s) {
    size_t idx;
    std::transform(s.begin(), s.end(), s.begin(), tolower);
    node* rt = &root;
    for (std::string::iterator i = s.begin(); i != s.end(); i++) {
        idx = _CHARS.find(*i);
        if (idx < MAX_NODES) {
            if (!rt->next[idx]){
                return std::vector<std::string>();
            }
            rt = rt->next[idx];
        }
    }
    if (rt->isWord) return rt->files;
    return std::vector<std::string>();
}
node* addWord(std::string s) {
    size_t idx;
    node *rt = &root, *n;
    for (std::string::iterator i = s.begin(); i != s.end(); i++) {
        idx = _CHARS.find(*i);
        if (idx < MAX_NODES) {
            n = rt->next[idx];
            if (n){
                rt = n;
                continue;
            }
            n = new node(*i);
            rt->next[idx] = n;
            rt = n;
        }
    }
    rt->isWord = true;
    rt->count++;
    return rt;
}
node root;
};

class index {
public:
void add(std::string s, std::string fileName) {
    std::transform(s.begin(), s.end(), s.begin(), tolower);
    std::string h;
    int freq=0;
    for (std::string::iterator i = s.begin(); i != s.end(); i++) {
        if (*i == 32) {
            pushFileName(addWord(h), fileName);
            h.clear();
            continue;
        }
        h.append(1, *i);
    }
    if (h.length()){
        pushFileName(addWord(h), fileName);
    }
}
void findWord(std::string s, map<string, int> mFilesFreq) {
    std::vector<std::string> v = find(s);
    if (!v.size()) {
        std::cout <<"'"<< s + "' is not found!\n";
        return;
    }
    std::cout << "'" << s << "' is found in:\n";
    for (std::vector<std::string>::iterator i = v.begin(); i != v.end(); i++) {
        std::cout << *i << "\n";

    }
    std::cout << "frequency is : ";

}

或更好:

<a href="#" onclick="window.open('apache.org', '_blank');" class="logo-css"></a>