看起来应该相当简单,但我无法让它发挥作用。我只是希望resourcesPressed()事件在同一浏览器中更改为其他URL。我的代码:
openBrowser() {
const options: ThemeableBrowserOptions = {
toolbar: {
height: 65,
color: '#008ba6ff'
},
title: {
color: '#ffffffff',
showPageTitle: false,
},
closeButton: {
image: 'home',
align: 'left',
event: 'closePressed'
},
customButtons: [
{
image: 'resources',
align: 'right',
event: 'resourcesPressed'
}, {
image: 'cbt',
align: 'right',
event: 'cbtPressed'
}, {
image: 'chat',
align: 'right',
event: 'homechatPressed'
}, {
image: 'contact',
align: 'right',
event: 'contectPressed'
},
],
backButtonCanClose: true
};
const browser: ThemeableBrowserObject = this.themeableBrowser.create('https://homeweb.ca/dashboard', '_blank', options);
browser.on('closePressed').subscribe(data => {
browser.close();
});
browser.on('resourcesPressed').subscribe(data => {
browser.open('https://google.ca/', '_self', options)
});
}
resourcesPressed的当前代码不起作用(属性'打开'类型' ThemeableBrowserObject'上不存在)。这应该是什么?
答案 0 :(得分:0)
我假设您正在使用此插件:https://github.com/initialxy/cordova-plugin-themeablebrowser
我这样做:
zip
我无法看到ThemeableBrowserObject的用途,而.create()也不存在。
如果它像InAppBrowser一样工作,那么每次调用open()都会打开一个新的浏览器视图。
您是否在项目中添加了cordova-plugin-themeablebrowser?
答案 1 :(得分:0)
使用executeScript解决:
openBrowser(pageToOpen) {
const options: ThemeableBrowserOptions = {
toolbar: {
height: 65,
color: '#008ba6ff'
},
title: {
color: '#ffffffff',
showPageTitle: false,
},
closeButton: {
image: 'home',
align: 'left',
event: 'closePressed'
},
customButtons: [
{
image: 'resources',
align: 'right',
event: 'resourcesPressed'
}, {
image: 'cbt',
align: 'right',
event: 'cbtPressed'
}, {
image: 'chat',
align: 'right',
event: 'homechatPressed'
}, {
image: 'contact',
align: 'right',
event: 'contectPressed'
},
],
backButtonCanClose: true
};
const browser: ThemeableBrowserObject = this.themeableBrowser.create(pageToOpen, '_blank', options);
browser.on('closePressed').subscribe(data => {
browser.close();
});
browser.on('cbtPressed').subscribe(data => {
browser.executeScript({
code: "window.location.href ='www.example1.com';"
});
});
browser.on('resourcesPressed').subscribe(data => {
browser.executeScript({
code: "window.location.href ='www.example2.com';"
});
});
}