首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >更改当前可选浏览器窗口的URL

更改当前可选浏览器窗口的URL
EN

Stack Overflow用户
提问于 2018-06-07 03:51:05
回答 2查看 1K关注 0票数 0

这看起来应该是相当简单的,但我不能让它工作。我只想让resourcesPressed()事件在同一浏览器中更改为不同的URL。我的代码:

代码语言:javascript
复制
  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”)。这应该是什么?

EN

回答 2

Stack Overflow用户

发布于 2018-06-09 01:04:15

使用executeScript解决:

代码语言:javascript
复制
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';"
      });
    });
  }
票数 1
EN

Stack Overflow用户

发布于 2018-06-07 05:11:59

我假设您正在使用这个插件:https://github.com/initialxy/cordova-plugin-themeablebrowser

我会这样做:

代码语言:javascript
复制
const browser = cordova.ThemeableBrowser;

我不明白ThemeableBrowserObject是用来做什么的,而且.create()也不存在。

如果它的工作方式类似于InAppBrowser,那么每次调用open()都会打开一个新的浏览器视图。

你在项目中添加cordova-plugin-themeablebrowser了吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50728476

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档