4 Replies Latest reply on Jan 2, 2017 5:42 PM by Scythron

    Open links in different browsers

    Scythron Level 1

      Hi, this is my Phonegap app. I'm trying to create an Android and iOS app that can open IP addresses from different browsers found on different devices (iPhone, Galaxy Tab 2, Nexus 6P, iPad, etc.) For example I may have a local IP address I want to open in Firefox, Chrome, and Safari on iOS devices, and Firefox, Chrome, and the 'Internet' browser found on Android devices. From my research, it seems like you can only open the default browser with the In App Browser plugin. Is there any other way of opening links so someone has the option of which browser they can use to open the link? One possible workaround I was thinking about is changing the default browser within Phonegap. Thank you.

        • 1. Re: Open links in different browsers
          VectorP Level 4

          If the user hasn't set a default application for a particular type of document, the OS will display a select list. The user then has the option of opening the document in his selected application "only this time" (so next time the same select list will appear) or "every time" (so this application will be set as the default).

          However, if the user has already set a particular application as the default for such document, that application will be used until the default is switched off or the user uninstalls that application.

           

          You, the developer of an app, are not in control of the user's decision on how to open documents on his device.

          • 2. Re: Open links in different browsers
            Scythron Level 1

            Thanks for your help. I've found several Stack Overflow posts on opening apps on the user's device with URL schemes.

             

            Here's one example: javascript - How to open Twitter and Facebook app with Phonegap? - Stack Overflow

             

            With the In App Browser plugin you can use:  window.open('twitter://user?screen_name=xerxesnoble', '_system', 'location=no'); to open a profile in the Twitter app if it's installed on the user's device. You can also use 'googlechrome://' to access Google Chrome for example. I have been unable to get this working in Phone Gap and I'm not sure if I'm missing something or this information is wrong all together.

            • 3. Re: Open links in different browsers
              VectorP Level 4

              With the In App Browser plugin you can use:  window.open(...

              No, you can't, unless you override the window.open() function. You should use cordova.InAppBrowser.open().

               

              You can also use 'googlechrome://' to access Google Chrome for example.

              Yes, if any application has registered an intent (on iOS: custom url scheme), then you can launch that application that way. However, not all browsers have such intent defined. Also, you need to whitelist such intents in your config.xml

              • 4. Re: Open links in different browsers
                Scythron Level 1

                I've gotten it working with Chrome and Safari on an iPhone 5 iOS 10.2, however with firefox:// it just loads a new tab in Firefox and disregards the link. Any potential fixes? I don't think there's a scheme for Safari so I just let the default browser open.

                 

                 

                HTML

                 

                <select class="browsers">

                <option value="">Select A Browser</option>

                </select>

                 

                JS

                 

                Inserts links based on appAvailability plugin for browsers.

                 

                $('select.browsers').append('<option value="googlechrome://nba.com">Google Chrome</option>');

                $('select.browsers').append('<option value="firefox://nba.com">Mozilla Firefox</option>');

                $('select.browsers').append('<option value="http://nba.com">Safari</option>');

                 

                 

                Here's the code I'm using to launch the browser:

                 

                  $('select.browsers').on('change', function() {

                                    cordova.InAppBrowser.open($('select.browsers option:checked').val(), '_system', 'location=yes');

                   });