/    Sign up×
Community /Pin to ProfileBookmark

Javascript cookie check help needed

Hi,

I need your help with javascript.

One one page I’m trying to show a layer only if the visitor hasn’t been on another page. The setCookie and getCookie functions work great, the showlayer function works great. The problem is that I’m not able to execute the showlayer function when no cookie is found. I’ll post the code below so you can take a look at it.

The function that shows/hides the layer:

[code]
function OpenPop(DivID, iState) // 1 visible, 0 hidden
{

if(document.layers) //NN4+
{
document.layers[DivID].visibility = iState ? “show” : “hide”;
}
else if(document.getElementById) //gecko(NN6) + IE 5+
{
var obj = document.getElementById(DivID);
obj.style.visibility = iState ? “visible” : “hidden”;
}
else if(document.all) // IE 4
{
document.all[DivID].style.visibility = iState ? “visible” : “hidden”;
}
}
[/code]

The code from the body:

[code]
<body onLoad=”begintimer()”>

<!– Start Floating Layer –>
<div id=”FloatingLayer” style=”position:absolute;width:400px;left:100;top:100;visibility:hidden”>
<p align=”center”><a href=”#” onClick=”ClosePop(‘FloatingLayer’,0);return false”><font color=”#000000″ size=”2″ face=”arial” style=”text-decoration:none”><img src=”donate.gif”></font></a></p>
</div>
<!– End Floating layer –>

<script type=”text/javascript” language=”JavaScript”>
<!–
if getCookie(“here”)!=”yes” OpenPop(‘FloatingLayer’,1);
// –>
</script>
</body>
[/code]

Here’s the link to a live test:
[url]http://www.3afaceri.ro/fbb/cookie[/url] – The page that contains the layer that shoul show only if the next page hasn’t been viewed.
[url]http://www.3afaceri.ro/fbb/cookie/donate.htm[/url] – The page that adds the cookie.

Hope you can help me with that 😮 .

Thanks in advance,
Valentin

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@JonaMar 29.2005 — [font=trebuchet ms]You need parentheses around your if condition.[/font]

<i>
</i>if (getCookie("here")!="yes") OpenPop('FloatingLayer',1);
Copy linkTweet thisAlerts:
@js_prof_consMar 29.2005 — I believe this was crossposted, in addition to the user finding the answer.
Copy linkTweet thisAlerts:
@JonaMar 30.2005 — I believe this was crossposted, in addition to the user finding the answer.[/QUOTE]
[font=trebuchet ms]Do you know where? I haven't seen another post by this member today.

Edit: It looks like [url=http://www.webdeveloper.com/forum/showthread.php?t=60845]you're right[/url], but it's a duplicate post, not a cross-post. Thanks for letting me know, though.[/font]
Copy linkTweet thisAlerts:
@valentin_cmauthorMar 30.2005 — Hi,

Have I done something wrong? If so, I'm sorry... but I would like to know what was it so it doesn't happen again.


Regards,

Valentin
Copy linkTweet thisAlerts:
@JonaMar 30.2005 — [font=trebuchet ms]Valentin,

Yesterday, being the very observant person I am, I noticed that the forums were slow. You didn't do anything wrong, even though you posted two threads, because I doubt you were aware that you posted the thread the first time. Thinking that it failed to post the thread due to such a slow speed, you probably hit "Create new thread" again, creating another thread. So, sometimes it's best to make sure your thread was posted before trying to post it again, even if it seems like it wasn't posted. That way you can avoid asking the question more than once.

Again, you didn't do anything wrong, it was merely an accident.[/font]
Copy linkTweet thisAlerts:
@valentin_cmauthorMar 30.2005 — Ok, thanks for making that clear ? Will try to avoid letting that happen again.
×

Success!

Help @valentin_cm spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...