xyz is not defined

S

scuniverse

I'm building a PHP game but I need a javascript to check if players
have clicked or not the Adsense link, currently the script works just
fine however in the IE browser it shows an error "Object expect" and
Firefox says "ad is not defined" (in the JS console).

I call the code like this right before the Adsense code

<script type="text/javascript" src="../js/ad_track.js"></script>
<div id="rightcol" onmouseover="javascript:ad();">


and the ad_track.js has this (it's part of the
http://www.digitalmediaminute.com/ Adsense clicks, I've just changed it
to suit my needs)

// incredibly funky onload add-event scripting, for all browsers

if(typeof window.addEventListener != 'undefined')
{
//.. gecko, safari, konqueror and standard
window.addEventListener('load', adsense_init, false);
}
else if(typeof document.addEventListener != 'undefined')
{
//.. opera 7
document.addEventListener('load', adsense_init, false);
}
else if(typeof window.attachEvent != 'undefined')
{
//.. win/ie
window.attachEvent('onload', adsense_init);
}

//** remove this condition to degrade older browsers
else
{
//.. mac/ie5 and anything else that gets this far

//if there's an existing onload function
if(typeof window.onload == 'function')
{
//store it
var existing = onload;

//add new onload handler
window.onload = function()
{
//call existing onload function
existing();

//call adsense_init onload function
adsense_init();
};
}
else
{
//setup onload function
window.onload = adsense_init;
}
}

function adsense_init () {

if (document.all) { //ie

var el = document.getElementsByTagName("iframe");

for(var i = 0; i < el.length; i++) {
if(el.src.indexOf('googlesyndication.com') > -1) {
adUnit = i+1;
browser = "IE";
adunitsize = el.width + "x" + el.height;
el.onfocus = trackAdsense;
}
}

} else { // firefox

window.addEventListener('beforeunload', doPageExit, false);
window.addEventListener('mousemove', getMouse, true);

}

}

//for firefox
var px;
var py;
var adUnit = "";
var browser = "";
var adunitsize = "";

function getMouse(e) {
px=e.pageX;
py=e.clientY;
}

function findY(obj) {
var y = 0;
while (obj) {
y += obj.offsetTop;
obj = obj.offsetParent;
}
return(y);
}

function findX(obj) {
var x = 0;
while (obj) {
x += obj.offsetLeft;
obj = obj.offsetParent;
}
return(x);
}

function doPageExit(e) {

var ad = document.getElementsByTagName("iframe");
for (var i = 0; i < ad.length; i++) {
var adLeft = findX(ad);
var adTop = findY(ad);
var inFrameX = (px > (adLeft - 10) && px < (parseInt(adLeft) +
parseInt(ad.width) + 15));
var inFrameY = (py > (adTop - 10) && py < (parseInt(adTop) +
parseInt(ad.height) + 10));

if (inFrameY && inFrameX) {
adUnit = i+1;
browser = "Firefox";
adunitsize = ad.width + "x" + ad.height;
trackAdsense();

}
}

}

//end for firefox

function trackAdsense() {
var path = 'ad_log.php';

var data = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try { data = new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e) { try { data = new ActiveXObject("Microsoft.XMLHTTP"); }
catch (E) { data = false; } }
@end @*/
if (!data && typeof XMLHttpRequest!='undefined') data = new
XMLHttpRequest();
if (data) data.open("GET", path, false); data.send(null);


}


Any idead ? the code works just fine but the error is unwanted ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top