jquery.dfp.js icon indicating copy to clipboard operation
jquery.dfp.js copied to clipboard

Insertion of gpt.js fails when the document doesn't have existing scripts

Open venkatkarun opened this issue 9 years ago • 3 comments

Not having scripts in the head or body might be weird but is quite prevalent as can be gauged by websites like http://www.csszengarden.com/215/. It will be nice to make jquery.dfp defensive as opposed to failing badly in such a scenario.

TypeError: Cannot read property 'parentNode' of undefined
at dfpLoader (chrome extension://bekccbechiigcepdoebmbganlaehelkj/bower_components/jquery.dfp/jquery.dfp.js:545:17)


 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);

venkatkarun avatar Feb 19 '16 17:02 venkatkarun

How do you insert the script without having any script-Blocks on the page?

Also, the lib requires jQuery. How are you using it?

On 19. feb. 2016, at 18.16, Venkat Karun [email protected] wrote:

Not having scripts in the head or body might be weird but is quite prevalent as can be gauged by websites like http://www.csszengarden.com/215/. It will be nice to make jquery.dfp defensive as opposed to failing badly in such a scenario.

TypeError: Cannot read property 'parentNode' of undefined at dfpLoader (chrome extension://bekccbechiigcepdoebmbganlaehelkj/bower_components/jquery.dfp/jquery.dfp.js:545:17)

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); — Reply to this email directly or view it on GitHub.

soreng avatar Feb 19 '16 18:02 soreng

The parent script that requires $.dfp is inserted as a chrome extension content script. jquery itself is required from the parent script.

venkatkarun avatar Feb 19 '16 18:02 venkatkarun

Hey @venkatkarun send me a pull request with something that works for your page and I will make sure it works elsewhere and merge it.

coop182 avatar Feb 22 '16 08:02 coop182