这看起来应该是相当简单的,但我不能让它工作。我只想让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)
});
}
打开的当前代码不起作用(类型“ThemeableBrowserObject”上不存在属性“resourcesPressed”)。这应该是什么?
发布于 2018-06-09 01:04:15
使用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';"
});
});
}
发布于 2018-06-07 05:11:59
我假设您正在使用这个插件:https://github.com/initialxy/cordova-plugin-themeablebrowser
我会这样做:
const browser = cordova.ThemeableBrowser;
我不明白ThemeableBrowserObject是用来做什么的,而且.create()也不存在。
如果它的工作方式类似于InAppBrowser,那么每次调用open()都会打开一个新的浏览器视图。
你在项目中添加cordova-plugin-themeablebrowser了吗?
https://stackoverflow.com/questions/50728476
复制相似问题