我正在使用离子Cordova应用内浏览器插件
constructor(private iab: InAppBrowser){
const browser = this.iab.create('https://www.sample.com'_self',{location:'no'}); /*3*/
this.browser.on('loadstart', event => {
alert('loadstart event'); // not fired
});
this.browser.on('loaderror', event => {
alert(' error'); // not fired
});
this.browser.on('exit', event => {
alert('exit event'); // not fired
});
}
但是loadstart,loaderror,退出事件不起作用。
谢谢..!
答案 0 :(得分:0)
首先检查platform.ready()事件在对进程进行计数之后。
constructor(private iab: InAppBrowser){
platform.ready().then(() => {
if (typeof cordova !== 'undefined') {
//Do your process
const browser = this.iab.create('https://www.sample.com'_self',{location:'no'}); /*3*/
this.browser.on('loadstart', event => {
alert('loadstart event'); // not fired
});
this.browser.on('loaderror', event => {
alert(' error'); // not fired
});
this.browser.on('exit', event => {
alert('exit event'); // not fired
});
});
}
}
答案 1 :(得分:0)
使用目标 "_blank"
而不是 "_self"
,例如:
const browser = this.iab.create(
'https://www.sample.com',
'_blank',
{location:'no'}
);
答案 2 :(得分:0)
如果您使用的是最新的 ionic 版本,那么以下是为 inappbrowser 调用每个事件的方式:
openInAppBrowser(){
const options:any = {
closebuttoncolor: "#ffffff",
lefttoright: 'yes',
hideurlbar: 'yes',
fullscreen: 'yes',
hardwareback: 'no',
toolbarcolor: '#145a7b',
zoom: 'no',
useWideViewPort: 'no',
hidenavigationbuttons: 'yes',
footer: 'no',
message: "Hello",
toolbar : 'no',
location:'no'
}
let browser = this.iab.create(url, '_blank', options);
browser.on('loadstop').subscribe(async event =>{
//your logic goes in here....
});
browser.on('loadstart').subscribe(async event =>{
//your logic goes in here....
});
browser.on('loaderror').subscribe(async event =>{
//your logic goes in here....
});
browser.on('beforeload').subscribe(async event =>{
//your logic goes in here....
});
browser.on('message').subscribe(async event =>{
//your logic goes in here....
});
}