Cordova 更改当前主题浏览器窗口的URL
看起来这应该相当简单,但我无法让它工作。我只希望resourcesPressed()事件在同一浏览器中更改为不同的URL。我的代码:Cordova 更改当前主题浏览器窗口的URL,cordova,ionic-framework,inappbrowser,Cordova,Ionic Framework,Inappbrowser,看起来这应该相当简单,但我无法让它工作。我只希望resourcesPressed()事件在同一浏览器中更改为不同的URL。我的代码: openBrowser() { const options: ThemeableBrowserOptions = { toolbar: { height: 65, color: '#008ba6ff' }, title: { color: '#ffffffff',
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”上不存在属性“open”)。这应该是什么?我假设您正在使用此插件: 我会这样做:
const browser = cordova.ThemeableBrowser;
我看不到ThemeableBrowserObject的用途,并且.create()不存在
如果它的工作方式与InAppBrowser类似,那么每次调用open()都会打开一个新的浏览器视图
是否将cordova插件themeablebrowser添加到项目中?使用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';"
});
});
}
我正在使用那个插件,是的。它在其他方面都很好,我只是无法让我的自定义按钮在同一窗口中更改URL。看起来应该很简单,但什么都没用。