The provided DFP Google script is indicated as a parser lock, cross-start script

I have the following standard code provided by Google DFP . Unfortunately, it appears as a parsing lock, cross-origin script, because it is implemented usingdocument.write

<script>
 (function() {
   var useSSL = 'https:' == document.location.protocol;
   var src = (useSSL ? 'https:' : 'http:') +
   '//www.googletagservices.com/tag/js/gpt.js';
   document.write('<scr' + 'ipt src="' + src + '"></scr' + 'ipt>');
 })();
</script>

I find this very strange because it is a standard DFP script from Google itself. Is there an updated version that I should use?

+4
source share
1 answer

You can use this:

(function () {
    var gads = document.createElement('script');
    gads.async = true;
    gads.type = 'text/javascript';
    var useSSL = 'https:' === document.location.protocol;
    gads.src = (useSSL ? 'https:' : 'http:') +
        '//www.googletagservices.com/tag/js/gpt.js';
    var node = document.getElementsByTagName('script')[0];
    node.parentNode.insertBefore(gads, node);
}());
+1
source

Source: https://habr.com/ru/post/1657428/


All Articles