cordova phonegap: handling links from within inappbrowser (need external links to open new browser or open in system browser)

早过忘川 提交于 2019-12-06 11:56:26

问题


I made a phonegap/cordova application that just skins a mobile friendly website. I'm loading the website via the InAppBrowser plugin fullscreen (no address bar or 'next' buttons)

This works fine and dandy, but when you click on an external link from the website, it changes the location on the current browser and there is no way to return :(

I am trying to use the executeScript function to send a script to the InAppBrowser to catch links that I want to load in a new browser, but the window.open call just changes the url of the existing full screen one and doesn't open a new one.

Another option would be to open in the system browser, but that isnt working either.

Here is the code I am calling with app.initialize()

initialize: function() {
  document.addEventListener('deviceready', function () {
    //opening my initial window
    var ref = window.open('http://www.mywebsite.com', '_blank', 'location=no,toolbar=no');
    ref.addEventListener('loadstop', function() {
        //when the initial window finishing loading, execute this script
        ref.executeScript(
        {code: "$(document).on('click','a',function(e){
            var $this = $(this);
            if($this.hasClass('external-link')){
            //attempt to load a new inappbrowswer for .external-linl
            var newWindow = window.open($this.attr('href'), '_blank', 'location=yes,toolbar=yes')};
            e.preventDefault })"
        });
    });
  }, false);
}

Thanks for any guidance you can provide!

来源:https://stackoverflow.com/questions/25578217/cordova-phonegap-handling-links-from-within-inappbrowser-need-external-links-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!