Вам не нужно связываться с событием onload. Просто привяжите к событию DOMContentLoaded
.
Поскольку вы уже включили jQuery на свою страницу, это можно сделать, используя .ready
:
$(document).ready(function() {
var innerHTML = document.body.innerHTML;
/* If you want to use a RegExp, use the following:
var regexp = /ad\.doubleclick\.net/gi; // Note: escaped dot
var matches = innerHTML.match(regexp);
matches = matches ? matches.length : 0; // matches can be `null`
*/
// This is more effective:
var matches = innerHTML.split('ad.doubleclick.net').length - 1;
alert('Found ' + matches + ' tags.');
console.log( innerHTML );
});