Forum Moderators: open
i run a counter service which involves placing a snippet of javacsript on a page to send the data back. The scenario is i've come across someone who wants to track image views, these images are desktop backgrounds that get openened in a popup window that is created via javascript, now i need to put the tracking code inside that window, the popup code uses 'write in' so i tried to also write in the tracking javascript, but the clsing < /script> in my tracking code closes the popup script prematurely, could someone have a look please:
i've bolded the part i added and the closing script tag is in italics that's causing the problem :)
<script>
PositionX = 0;
PositionY = 0;
defaultWidth = 1044;
defaultHeight = 788;
var AutoClose = true;
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
function popImage(imageURL,imageTitle){
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
writeln('width=100-(document.body.clientWidth-document.images[0].width);');
writeln('height=100-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');
writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="Wallpaper" src='+imageURL+' style="display:block"></body></html>');
writeIn('<script language="JavaScript" type="text/javascript" src="tracker.js"></script>');
writeIn('<noscript><img alt="" src="http://www.url.com/tracker.php?id=USERNAME&st=img"><a href="http://www.url.com">Free invisible counter</a></</noscript>');
close();
}}
</script>
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
writeln('width=100-(document.body.clientWidth-document.images[0].width);');
writeln('height=100-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');
writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
writeIn('<script language="JavaScript" type="text/javascript" src="tracker.js"></sc'+'ript>');
writeIn('<noscript><img alt="" src="http://www.url.com/tracker.php?id=USERNAME&st=img"><a href="http://www.url.com">Free invisible counter</a></</noscript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="Wallpaper" src='+imageURL+' style="display:block"></body></html>');
writeIn('<script language="JavaScript" type="text/javascript" src="tracker.js"></script>');
writeIn('<noscript><img alt="" src="http://www.url.com/tracker.php?id=USERNAME&st=img"><a href="http://www.url.com">Free invisible counter</a></</noscript>');
close();
}}
</script>
If no one has picked this up by this evening (PDT), I'll try to give it a go.
Does the script work to your satisfaction without the counter?
Also, many web hosts offer server side includes (SSI) that are counters. If your host does, it would be easier than this stuff.
Note that in the original code, there are lines with broken-up script tags already. Your code just needs to go in the head just after the original, like this partial copy:
. . .
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>'+ '<scr'+'ipt src="tracker.js"></sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="Wallpaper" src='+imageURL+' style="display:block"></body></html>');
This assumes that the external script file tracker.js does what you need it to do, which I have to wonder. It makes little sense to include the noscript tags & code for a window that won't exist if the browser doesn't have JavaScript turned on.
yeah your reading into it is correct. Someone come along on my support forum for the counter who rewrote the popup generator to not create a page each time but to call a blank html page in which the image is inserted, and ofcourse this made it easier as the user can just put the tracking code on that blank html page.
Yeah if javascript was turned off the whole thing would not work anyway, this wasn't a normal scenario for someone wanting to use my counter.
your time is much appreciated :)
leo