0

I am using ionic framework and Angular JS.

I am not sure where to start to track start of a web request.

For end request, I write a directive with onLoad tag.

here is the code

Directive.js

app.directive('iframeOnload', [function(){
    return {
        scope: {
            callBack: '&iframeOnload'
        },
        link: function(scope, element, attrs){
            element.on('load', function(){
                return scope.callBack({DOMelement: this});
            })
        }
    }}]);

At the HTML

<iframe id="webFrame" iframe-onload="iframeLoadedCallBack()" style="width:100%;height:650px;" ng-src='{{goToURL}}' ng-hide='hideIFrame'></iframe>

At the Controller The callback function is

    $scope.iframeLoadedCallBack = function() {
        console.log('iframeLoadedCallback');
        // finished web request callback do something here
    };

I guess there is something similar for start of the web request. And I need to track the send request URL.

I am an iOS developer, And actually I would like to do something similar to this protocol UIWebViewDelegate.

Thanks a lot

Ken Hui
  • 368
  • 3
  • 17
  • turned out that interceptors from $httpProvider don't catch requests of iframe, my bad, sorry. – Rasalom Dec 12 '14 at 08:22
  • The interceptors catch all the request of $http object include the ui-route. I hope it helps someone using alternative method for loading the external link. – Ken Hui Dec 12 '14 at 08:42
  • it also catches all requests for template html, that's why I thought it should help with iframe. – Rasalom Dec 12 '14 at 09:03

2 Answers2

0

Although it may not work perfectly, at the iframeLoadedCallback

you could add the following code

 var webFrame = angular.element(document.getElementById('webFrame'));
 webFrame[0].contentDocument.onclick = $scope.clickOnIframe;

and it will track every click event inside the iframe, rest of it would be hard code to track by ID, tag, class etc inside the event.

I hope it helps someone has similar question.

Ken Hui
  • 368
  • 3
  • 17
0

You can track all web requests using NSURLProtocol hope this may help.

Zahid
  • 552
  • 3
  • 11