Cordova Phonegap and Google Maps v3 javascript api: How to add backbutton functionality when clicking either the license link or the Google maps logo

后端 未结 3 2062
囚心锁ツ
囚心锁ツ 2021-01-13 09:39

Background: The Cordova phonegap 2.2 application running on Android allows listening to the backbutton event

document.addEventListener(\"bac         


        
3条回答
  •  一个人的身影
    2021-01-13 10:03

    .live() has been removed in jQuery v1.9 and is deprecated in Zepto v1.0rc1, so here's a revised version of kvaale's answer that should work well with the latest frameworks.

    This version also uses PhoneGap/Cordova's InAppBrowser code, enabling you to either open the links in the InAppBrowser (using '_blank') or the system web browser (using '_system').

    function directUrlToExternalBrowser(urlPattern){
        var pattern = "a[href^='"+urlPattern+"']";      // detect all urls starting with urlPattern
    
        $(document).on('click', pattern, function(e){
            e.preventDefault();
            var ref = window.open($(pattern).attr("href"), '_system', '');      // '_system' will open the system web browser, '_blank' will open the InAppBrowser
        });
    }
    

    Then put the following code in your $(document).ready() function...

    directUrlToExternalBrowser("http://maps.google.com/maps");
    directUrlToExternalBrowser("http://www.google.com/intl");
    

    If you want to detect all "a href" links (not just those for Google Maps), use the following code instead...

    directUrlToExternalBrowser("http://");  
    directUrlToExternalBrowser("https://");      
    

提交回复
热议问题