If you checked the result of the url request (make sure adBlock is off)
https:
You will see the actual result.
document.write('<script type="text/javascript" src="//wlbetclic.eacdn.com/TrafficOpt/s.5.4.min.js?t=1"></script>'); document.write('<script type="text/javascript" src="//wlbetclic.eacdn.com/wlbetclic/img/js/Affiliate_12824.js?t=20160224"></script>'); //other lines omitted for brevity
Thus, this file executes document.write , which obviously will not work in angular, simply because it is completely different (although you can somehow call the digest loop, you still do not have access to modify this script file generated by a third-party server and has its own variables)
What would I do - create a page like ad.html like index.html or 404.html, then request this file from angular (not as a template, but as a view file) as an iframe src with custom attributes
And I would use a custom DOM element and populate the content with jQuery or with angular, looking at the jQuery sample below
I will also need the krux / postscribe plugin because you cannot use document.write in async html files
<ad-holder url="https://wlbetclic.adsrv.eacdn.com/S.ashx?btag=a_17172b_14837c_&affid=12824&siteid=17172&adid=14837&c="></ad-holder> <div class="black-widow"> <ad-holder url="http://google.com" width="100" height="40"></ad-holder> </div> <script> </script> <scrip> angular.module('app', []).directive('adHolder', function(){ return { restrict: 'E', scope: { url: '@' }, //you could also execute in compile-phase link: function(scope, element, attribute){ var $iframe = angular.element(document.createElement('iframe')); $iframe.attr('src', 'ad.html?url=' + scope.url); element.html($iframe); } } }); </script>
And ad.html will look like
<body> <div id="ad"></div> <script> function getQueryVariable(variable) { var query = window.location.search.substring(1); //for the sake of simplicity we expect only 1 param (url) return query.replace('url=', ''); } var adUrl = getQueryVariable('url'); if (adUrl) postscribe('#ad', '<script src="' + adUrl + '"><\/script>'); else { var $h1 = $(document.createElement('h1')); $h1.text('No ad available'); $(document.body).append($h1); } </script> </body>
The best part of this solution is that you can reuse the same user element with a different url attribute for any other ads
Checkout jQuery real working demo
Although this demo uses jQuery heavily, it is easy to configure for the angular version that I suggest you do as homework =)