ionic 3在应用程序浏览器中获取ionic应用程序中的点击事件听说是我的代码
let target = "_blank";
const browser = this.iab.create(url,target,this.options);
browser.on('loadstop').subscribe(event => {
browser.executeScript({code: `$("[data-menu=logout]").attr('data-menu','logout_custom');
$("[data-menu=logout_custom]").attr('href',url);
$("[data-menu=logout_custom]").on('click',function(){
webkit.messageHandlers.cordova_iab.postMessage('REACT_EXIT');
this.backendMessage('REACT_EXIT')
})
`});
});
this.backendMessage('REACT_EXIT'(这个函数在我的离子应用程序中我需要在点击注销_自定义时调用此函数
试试这个
let target = "_blank";
const browser = this.iab.create(url,target,this.options);
browser.on('loadstop').subscribe(event => {
console.log(event,"loadstop");
browser.executeScript({code: $("[data-menu=logout]").attr('data-menu','logout_custom');
$("[data-menu=logout_custom]").click(function(){
var message = 'REACT_EXIT';
var messageObj = {my_message: message};
var stringifiedMessageObj = JSON.stringify(messageObj);
window.webkit.messageHandlers.cordova_iab.postMessage(stringifiedMessageObj);
});}).then((cookie) =>{
console.log(cookie,"cookie");
}).catch((error)=>{
console.log(error,"error");
});
});
browser.on('message').subscribe((event) => {
console.log('postmessage received',event);
const postObject:any = event
if(postObject.data.my_message == 'REACT_EXIT'){
console.log(postObject.data.my_message);
}
console.log('other message');
})