golear
1
In the Cordova documentation here https://github.com/apache/cordova-plugin-inappbrowser#inappbrowserexecutescript I see that you can pass execute script a callback function that gets called after the passed script has executed.
I see no mention of this made in the Ionic documentation: http://ionicframework.com/docs/v2/native/inappbrowser/
Is there anyway to attach a callback that receives the return value of the executed script (as mentioned in the cordova link above)?
1 Like
golear
2
Looks like I answered my own question. You can do something along the lines of:
let browser = new InAppBrowser('example-url.com');
browser.executeScript({code:'document.cookie;'}).then((cookie)=>console.log(cookie));
Would be nice if this was mentioned in the documentation instead of making no mention of return type (Promise) for executeScript.
3 Likes
Thank you golear. it helped.
Point to note to Ionic2. please add an example usage in documentation.
let browser = new InAppBrowser(‘example-url.com’);
browser.executeScript({code:‘document.cookie;’}).then((cookie)=>console.log(cookie));
I tried but it does’nt work. It opens the browser, but i can’t see any console log
Hi my friend, have you solved your problem?
I have the same problem to solve.
thanks!!!
pysam12
6
const browser = this.inappbrowser.create('example.com','_blank',{location:'no',clearcache:'yes',toolbar:'no'});
browser.on('loadstop').subscribe(function(event) {
browser.executeScript({code:'document.cookie;'}).then((cookie)=>{
console.log(cookie);
});
});
It works
2 Likes
Thank you golear, your answer saved my lots of time.
Hi, it works . Is it possible get the page source code? I tried using: document, document.documentElement.innerHTML but unsuccessfully.
with code = “var resultado = document.documentElement.innerHTML;alert(resultado);” it shows, however I need it on callbackfunction.
Hanzo
9
Hi am the same question, @viniciusfcf, did you solved?