Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get html from inappbrowser phonegap?

i make an application on phonegap. I need to get content html from inappbrowser when i click Close button at toolbar but it isnot working. this is my code:

var handleClose = function() {
    // get content html from here
}

ref.addEventListener('exit', handleClose);

Can someone help me?

like image 854
quang dung Avatar asked Dec 08 '22 05:12

quang dung


2 Answers

To help anyone in future, I've just stumbled across this same question and found a solution.

var inAppRef = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');
inAppRef.addEventListener('loadstop', function() {
  inAppRef.executeScript({
    code: "document.getElementsByTagName('html')[0].innerHTML"
  }, function(html) {
    alert(html);
  });
});

Remember you need to reference and include the InAppBrowser through phonegap / cordova.

like image 134
Ralpharoo Avatar answered Mar 03 '23 03:03

Ralpharoo


To build upon the answer from Ralphonzo, for the current version of in-app-browser (v3.0.0) and ionic (v4.6.0) and cordova (v7.1.0) with Angular (v7.2.8), this works for me:

ngOnInit() {
  this.browser = this.iab.create(domain + sso_url, '_blank', {});

  this.browser.on('loadstart').subscribe((event: InAppBrowserEvent) => {
    this.browser.executeScript({code: 'document.getElementsByTagName("html")[0].innerHTML'}).then( html => { console.log(html) });
  }
}
like image 39
Kate Sowles Avatar answered Mar 03 '23 04:03

Kate Sowles