Forum Moderators: open

Message Too Old, No Replies

using 'write in' to write javascipt into window

         

leoo24

11:01 am on Apr 11, 2004 (gmt 0)

10+ Year Member



hey guys :)

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>

Rambo Tribble

1:33 pm on Apr 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The command is writeln() with a lower-case "L", not an upper-case "I". It's as in "write line".

leoo24

2:10 pm on Apr 11, 2004 (gmt 0)

10+ Year Member



thankyou, still have the same problem though.

Rambo Tribble

2:28 pm on Apr 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, there are likely to be several problems with what you have. Nothing should be outside the body tags of the document being written. The existence of unbroken script tags within the strings being written will cause problems for some browsers. Just put the code you want within the original script block and you will at least be closer to success. Try to avoid script tags within a written character string unless you break them as in '<scr' + 'ipt>'

leoo24

3:03 pm on Apr 11, 2004 (gmt 0)

10+ Year Member



although javascript is chinese to me i see what you are saying but have no idea how to implement it, here's a stab:
also i saw that earlier on in the popup script they had used </sc'+'ript> so i tried replacing the clsing script tag i want to insert with that, would this work?

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>

Rambo Tribble

3:26 pm on Apr 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unfortunately, I don't have time this morning to address the syntax errors you have in this script. Quickly, your use of double and single quotes is going to cause problems and, since the counter is actually a PHP script, I think your invocation of the PHP has problems, too.

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.

leoo24

3:49 pm on Apr 11, 2004 (gmt 0)

10+ Year Member



no worries, whenever you can :)

the counter is a service i run, and this script is on a users site. As far as i know from having a look at the users site the popup script does seem to work fine.

Rambo Tribble

12:26 am on Apr 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It appears that this script opens a window from the original document, then writes an image to the window, resizing the window according to the image size. It does not appear that the window will allow any further browsing, but that it just hosts the one image. It appears that loading another image will have to start from the original document, and will create another window. If I'm correct in this assessment, it probably makes a little more sense to trigger your counter from the script in the original document, rather than from a script in the new window. However, it isn't a big deal either way.

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.

leoo24

6:02 pm on Apr 12, 2004 (gmt 0)

10+ Year Member



hi,

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