@George Siggouroglou:這不是用於元素的ID,最終將一個文檔中出現一個以上的時間是個好主意。取而代之的是讓代碼更加模塊化的好做法。
如果希望觸摸設備的也是不錯的選擇之前使用「點擊」,「點擊」,因爲它觸發速度更快,早於一點擊。檢查觸摸能力的東西,我喜歡使用modernizr,因爲它使功能檢測輕而易舉。
The jQuery Mobile tap event triggers after a quick, complete touch event that occurs on a single target object. It is the gesture equivalent of a standard click event that is triggered on the release state of the touch gesture. https://api.jquerymobile.com/tap/
希望幫助別人
**html code:**
<a class="ext-link" href="#">Google it</a>
或
<button class="ext-link" href="#">Google it</button>
的JavaScript(用jQuery):
//define tab or click event type on rool level (can be combined with modernizr)
iaEvent = "click";
if (typeof navigator !== "undefined" && navigator.app) {
iaEvent = "tap";
}
$('.ext-link').each.bind(iaEvent, function() {
if (typeof navigator !== "undefined" && navigator.app) {
// Mobile device.
var linktarget = this.attr("href");
navigator.app.loadUrl(linktarget, {openExternal: true});
} else {
// Possible web browser
window.open(linktarget, "_blank");
}
});
在我看來,它在Android中默認工作正常(但我使用Crosswalk插件也是...)。查看我的2015年答案,在WebView中打開'_self',在外部瀏覽器中打開'_blank':http://stackoverflow.com/questions/32208609/cordova-why-would-inappbrowser-plugin-be-required-to-open - 系統連接眉毛/ 32227524 – 2015-08-26 13:43:00