[thelist] Document.write Issue

Keith cache at dowebscentral.com
Tue Apr 30 10:31:01 CDT 2002


>I am trying to write one of my cookies in the body of my document.  For

>The code that searches for the existance of the cookie exists in the <head>
>of the page. If the cookie exists, the code in the <head> calls a function
>which I have placed in the body of the page:

If you are writing the contents of the cookie to the body, then test for
the cookie and capture it's contents in the body, not the head. The cookie
capture needs to be in the same script block as the document.write
statement. Just think of the cookie capture as part of the document.write
sequence. You cannot call a function in the body until after the body has
already rendured the code you are calling, which is too late for doing the
document.write in that spot on the page.

<script>
cookies=document.cookie.split(";")
for(i=0;i<cookies.length;++i){
   pair=cookies.split("=")
     if(pair[0].indexOf("myCookieName")!=-1){
       document.write(pair[1])
     }
}
</script>



keith

cache at dowebscentral.com




More information about the thelist mailing list