Problem with JavaScript Cookies (beginner)

D

duane

Dear Experts:

I have no experience using cookies with Javascript and stumble on a
weird problem on a very simple code I attached below. My problem is
whenever I want to access my page for the first time, e.g.
HelloCookie.HTML, the page never gets displayed (although the little
Microsoft flag in the top corner keeps waving indicating it is busy
looking or retrieving for the page). I waited for five minutes but
still nothing shown.

However, everytime I close the browser and try to re-open the same
page, the page will get displayed and the cookie will also be set to a
correct value. I want this to work the first time the user access my
page. In other words, I want the cookie to be set to the correct value
and have the page displayed without having the user to close the
browser and re-open it again.

What am I doing wrong?

==========================================================================
NOTE: To make sure my code runs correctly, I always clear up IE cache
after re-opening the browser for the second time, e.g. after the page
gets displayed and cookie value is set correctly. This is done by
going to TOOLS -> INTERNET OPTIONS -> DELETE FILES in IE. Otherwise,
it will just retrieve the file in the local cache where the correct
cookie value has been set.
==========================================================================

Thank you for your time.

PS: Below is the JScript code
(Process_Cookie.php: a PHP script which process the cookie further)



*********************** HelloCookie.HTML **************************
<HTML>
<HEAD>
<SCRIPT language="JavaScript">

// Check if user has visited this page before
function check()
{
if (document.cookie.indexOf('processed')!= -1)
document.cookie = "processed=yes; path=/";
imgObj = new Image();
imgObj.src = "Process_Cookie.php";
}
</SCRIPT>
</HEAD>

<BODY onLoad = "check();">
<P> HELLO WORLD!</P>
<img src = "myImage.jpg">
</BODY>
</HTML>
 

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,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top