Opening links in external device browser with Cordova/jQuery-mobile

后端 未结 5 1611
故里飘歌
故里飘歌 2021-01-17 23:09

I have a bunch of links in my app. I added rel=\'external\' target=\'_blank\' to all of them.

In the Ripple emulator, or in a regular desktop browser,

5条回答
  •  一生所求
    2021-01-17 23:47

    This has been really fickle with Cordova/PhoneGap in the last few releases, I believe because of the InAppBrowser work which might be a solution for you.

    What is working for us to launch in the external browser is:

    window.open("http://myurl.com", '_system');
    

    In our case, we want to find all external links and launch them in Safari/Chrome (and keep internal links in our Angular router). This probably isn't the most elegant solution, but we are doing this right now by capturing input events on the links and taking over the behavior like so:

            $(document).on('mousedown','a', function(e) {
                e.preventDefault();
                var elem = $(this);
                var url = elem.attr('href');
                if (url.indexOf('http://') !== -1) {
                    window.open(url, '_system');
                }
            });
    

    I hope that helps you a bit.

提交回复
热议问题