initialxy / cordova-plugin-themeablebrowser

Fork of org.apache.cordova.inappbrowser in an attempt to make it a bit more themeable and configurable to add some custom actions.
Apache License 2.0
294 stars 221 forks source link

change url on menu buttons click #157

Open aaharutyunyan opened 6 years ago

aaharutyunyan commented 6 years ago

Is it possible to open external links on menu button click event without restart ThemeableBrowser (I mean without close and run again) ? thanks

aaharutyunyan commented 6 years ago

var browser_obj = cordova.ThemeableBrowser; var browser = browser_obj.open(fullUrl, '_self', options); browser.addEventListener(cordova.ThemeableBrowser.EVT_ERR, function (e) { console.log(e.message); }); browser.addEventListener(cordova.ThemeableBrowser.EVT_WRN, function (e) { console.log(e.message); }); browser.addEventListener('loadstart', function (event) { $.mobile.loading('show', { text: 'Loading...', textVisible: true, theme: 'c', textonly: false, html: '' }); }); browser.addEventListener('loadstop', function (event) { $.mobile.loading('hide'); }); browser.addEventListener('helloPressed', function (e) { browser_obj.open('www.google.com', '_self', options); /// <-------- something like this console.log('----------------------------------------debuggg' + e); });

brycekirk commented 5 years ago

+1, I'd like to know this as well

brycekirk commented 5 years ago

Got it:

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.example.com';"
      });
    });
    browser.on('resourcesPressed').subscribe(data => {
      browser.executeScript({
        code: "window.location.href ='www.thisseemsmoredifficultthanitshouldbe.com';"
      });
    });
  }