Getting URL of InAppBrowser

前端 未结 4 780
故里飘歌
故里飘歌 2021-01-12 18:22

Using InAppBrowser I wish to get the URL of the site the user is currently on, when he chooses to close the InAppBrowser.

Adding an eventlistener for the exit event

4条回答
  •  無奈伤痛
    2021-01-12 18:48

    Getting URL of browser InAppBrowser in angularjs, Ionic

    You can get the url of the Opened window view (browser) by using the event handling of browser (InAppBrowser)

    As a example we are calling a twitter page and whenever the page change the url it will show the alert with the Url :

    var twitterWindow = window.open("https://twitter.com/", '_blank', 'location=no');
                        twitterWindow.addEventListener('loadstart',  function(event) {
                            alert("Current Event : "+ event.url);
                        });
    

    Here we use the "addEventListener" for handling the event of browser .

     window.open('local-url.html');                  
    // loads in the Cordova WebView 
    window.open('local-url.html', '_self');         
    // loads in the Cordova webView
    window.open('local-url.html', '_system');       
    // Security error: system browser, but url will not load (iOS)
    window.open('local-url.html', '_blank');        
    // loads in the InAppBrowser
    window.open('local-url.html', 'random_string'); 
    // loads in the InAppBrowser
    window.open('local-url.html', 'random_string', 'location=no'); 
    // loads in the InAppBrowser, no location bar
    

    To handle the events of the Browser we can use :

    var ref = window.open('http://whitelisted-url.com', '_blank');
    ref.addEventListener('loadstart', function(event) { alert(event.type + ' - ' + event.url); } );
    ref.addEventListener('loadstop', function(event) { alert(event.type + ' - ' + event.url); } );
    ref.addEventListener('loaderror', function(event) { alert(event.type + ' - ' + event.url + ' - ' + event.code + ' - ' + event.message); } );
    ref.addEventListener('exit', function(event) { alert(event.type); } );
    

    And to Close the InAppBrowser :

    var ref = window.open('http://whitelisted-url.com', '_blank');
    ref.close();
    

提交回复
热议问题