Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please Please Help.

Status
Not open for further replies.

enigma2212

Programmer
Sep 3, 2008
9
GB
Hi All You Experts,

Could someone please help me??
I have written a function which loads in the body of an asp page and checks to see if a user has a cookie already set and it if doesnt then it sets it and writes out some more javascript code (google analytics).

I have got the whole setting/retrieveing cookie bit sorted its just the writing of the additional javascript google analytics code. I have tried document.write but that doesn't help, it just spits out the rest of the code as text.

I have tried appending the script, noscript and img tags and setting attributes but then the script tag doesn't properly download the code from google. If succesful its supposed to show a link which says 'google site stats'.

The function is:

function testFunction(){
var c = getCookie(val);
if(!c){
alert('Setting New Cookie\nName :' + val);
setCookie(val, 'tracked', 1000);
}
else{
document.write('cookie set');
}

}

I would like the following code to be executed straight after the setCookie function is called:

<!-- Google Code for Lead Conversion Page -->
<script language="JavaScript" type="text/javascript">
<!--
var google_conversion_id = 1098528816;
var google_conversion_language = "en_GB";
var google_conversion_format = "1";
var google_conversion_color = "FFFFFF";
if (100.0) {
var google_conversion_value = 100.0;
}
var google_conversion_label = "Lead";
//-->
</script>
<script language="JavaScript" src="</script>
<noscript>
<img height="1" width="1" border="0" src="</noscript>

How would I go about doing this. Any help??
N.B. Its gots to be done in Javascript :(

Thanks
 
When is your "testFunction" function being called? if it's on or after the page is loaded, then the "document.write" call will overwrite everything else on the page, which you probably don't want.

If you replace "document.write" with "alert", does all work as expected?

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
BillyRay,

the function is called in teh body of the document.

I don't understand why I would want to alert it though??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top