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

后端 未结 5 1544
故里飘歌
故里飘歌 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-18 00:01

    I had issues with Jason Farnsworth's answer still firing the default action after the user returned to the app in iOS. So after a little tweaking of his code I arrived at the following and it behaved as expected.

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

提交回复
热议问题