window.onload = function(){ var img = document.getElementsByTagName('img'), len = img.length; for(var i = 0; i < len; i++) { if( img[i].src.indexOf(location.host + '/y.png') != -1 ) { alert('!'); return; } } }