window.close equivalent in Phonegap with InAppBrowser

前端 未结 2 1256
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 05:22

I open a new page with window.open(\"apphelp.html\", \"_blank\", \"location=no\"), and then it shows me a new window with my page. At the end of this page, I wo

相关标签:
2条回答
  • 2020-12-03 05:52

    I use a workaround... Since the inAppBrowser can be closed only with the back button or trough javascript. I display a close button from serverside that will change the current url firing also the event 'loadstop' letting to use the .close() method, in this way only the child browser will be closed, your app will remain in the same state.

    For example my server display a webpage with a close button, something like this:

    <a href="/mobile/close">Close</a>
    

    in my client side javascript (the Phonegap app):

    var ref = window.open(encodeURI(url), '_blank', options);
    ref.addEventListener('loadstop', function(event) {        
        if (event.url.match("mobile/close")) {
            ref.close();
        }
    });
    
    0 讨论(0)
  • 2020-12-03 05:55

    I transform for multi platform support like this:

    in the third page html and js

    closeBrowser(){
        if(history.length==1){
            window.open('mobile/close');
        }else{
            history.back();
        }
    }
    
    
    
    <a href="javascript:;" onclick="closeBrowser()">Close</a>
    

    in my client side javascript (the Phonegap app):

    var ref = window.open(encodeURI(url), '_blank','location=no');
     ref.addEventListener('loadstart', function(event) {
         if (event.url.match("mobile/close")) {
             ref.close();
         }
     }); 
    

    thanks the first floor!

    0 讨论(0)
提交回复
热议问题