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

executescript not working #8

Closed skhurams closed 9 years ago

skhurams commented 9 years ago

Hi i want to get current page title how do i get this. my ref.executescript is not working. heres what i have done so far

 function innAppInit(_url) {
 app.Log('browser news link=' + _url);
  if (_url == null) {
    _url = 'http://apache.org';
  }
var ref = cordova.ThemeableBrowser.open(_url, '_blank', {       

    statusbar: {
        color: '#239EC9'
    },
    toolbar: {
        height: 44,
        color: '#239EC9'
    },
    title: {
        color: '#FFFFFF',
        showPageTitle: false,
        staticText: 'Add New Web Page'
    },
    backButton: {
        image: 'back',
        imagePressed: 'back_pressed',
        align: 'left',
        event: 'backPressed'
    },
    forwardButton: {
        image: 'forward',
        imagePressed: 'forward_pressed',
        align: 'left',
        event: 'forwardPressed'
    },
    closeButton: {
        image: 'close',
        imagePressed: 'close_pressed',
        align: 'right',
        event: 'closePressed'
    },
    customButtons: [{
        image: 'share',
        imagePressed: 'share_pressed',
        align: 'right',
        event: 'event_getThumb'
    }],     
    backButtonCanClose: false
 });
}

     ref.addEventListener('loadstop', function(event) {
         try {

             ref.executeScript({
                     code: 'return document.title'
                 },
                 function(values) {
                     alert(values);
                     $('#txtDisplayName').val(values);
                 });
         } catch (e) {

         }
     });
initialxy commented 9 years ago

In order to reduce magical behaviour, there is now a flag to indicate if current page title should be shown. See showPageTitle

One thing to keep in mind is that staticText will override showPageTitle so you need to remove your staticText property. So it should look something like

title: {
    color: '#FFFFFF',
    showPageTitle: true
}
initialxy commented 9 years ago

O I see you are trying to retrieve document.title through executeScript. Can you please elaborate on how it's not working? What do you see from log? If you open Safari remote debugger and look at console, do you see any JavaScript errors?

skhurams commented 9 years ago

no errors actually when i run js debugger the code is not executed at all.

initialxy commented 9 years ago

The code you execute should be

document.title

Not

return document.title

eg:

ref.executeScript({
    code: 'document.title'
}, function(values) {
    alert(values);
});
skhurams commented 9 years ago

thanks it helped

anilk533 commented 8 years ago

HoW TO ADD LAODER IN IONIC themeable browser????????? and how to change title text dynamically when load start and load stops? currently iam adding laoder on on event start but it showing the loader in themebrowser. its showing when themebrowser closes.(i mean showing in prev page).

var ref = cordova.ThemeableBrowser.open(link, '_blank', {

                        statusbar: {
                            color: '#f24f4f'
                        },
                        toolbar: {
                            height: 40,
                            color: '#f24f4f'
                        },
                        title: {
                            color: '#FFFFFF',
                            showPageTitle: false,
                            staticText: 'Add New Web Page'
                        },
                        /*backButton: {
                            image: 'back',
                            imagePressed: 'back_pressed',
                            align: 'left',
                            event: 'backPressed'
                        },
                        forwardButton: {
                            image: 'forward',
                            imagePressed: 'forward_pressed',
                            align: 'left',
                            event: 'forwardPressed'
                        },*/
                        closeButton: {
                            image: 'close',
                            imagePressed: 'close_pressed',
                            align: 'right',
                            event: 'closePressed'
                        },
                        /*customButtons: [{
                            image: 'share',
                            imagePressed: 'share_pressed',
                            align: 'right',
                            event: 'event_getThumb'
                        }], */    
                        backButtonCanClose: false
                     });

        //}); 

        ref.addEventListener('loadstart', function(event) {
            $rootScope.LoaderShow();
        });
        ref.addEventListener('loadstop', function(event) {
            $ionicLoading.hide();
        });
        ref.addEventListener('event_getURL', function(event) {

        });
        ref.addEventListener('exit', function(event) {
            $ionicLoading.hide();
        });