Phonegap build - Open external page in InAppBrowser or childbrowser with no toolbar and close it?

后端 未结 2 783
执念已碎
执念已碎 2020-12-03 02:17
  1. I want to open an external page in the InAppBrowser or childbrowser, where I don\'t show any toolbar and where I can have a button in my externalpage that closes th

2条回答
  •  囚心锁ツ
    2020-12-03 02:46

    OK, problem 1 to close is solved. This is what I use to open an external page in the InAppBrowser. From the page that I load in the InAppBrowser, I can close the InAppBrowser itself, returning to my app from where I opened the browser.

    Create a page on your server - closeInAppBrowser.html that is just an empty html page, it doesn´t do anything

    I open the browser with this:

    open InAppBrowser
    
    var ref = null;
    function openInAppBrowserBlank(url)
    {
        try {
    ref = window.open(encodeURI(url),'_blank','location=no'); //encode is needed if you want to send a variable with your link if not you can use ref = window.open(url,'_blank','location=no');
             ref.addEventListener('loadstop', LoadStop);
             ref.addEventListener('exit', Close);
        }
        catch (err)    
        {
            alert(err);
        }
    }
    function LoadStop(event) {
             if(event.url == "http://www.mypage.com/closeInAppBrowser.html"){
                // alert("fun load stop runs");
                 ref.close();
             }    
        }
    function Close(event) {
             ref.removeEventListener('loadstop', LoadStop);
             ref.removeEventListener('exit', Close);
        } 
    

    And to close the InAppBrowser from the page that I opened in the browser(http://www.mypage.asp) I have a button-link like this.

    
    

    I hope it helps somebody else!

提交回复
热议问题