Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-13-2012, 09:51 PM   PM User | #1
reach100
New Coder

 
Join Date: May 2008
Posts: 34
Thanks: 6
Thanked 0 Times in 0 Posts
reach100 is an unknown quantity at this point
How do I bypass a splash page if someone has already seen it.

HI there, we have a splash page set up on http://www.sealfit.com. I would like a visitor to see the splash page a maximum of 3 times. If they fail to sign up for the offer, and click "No Thanks, Take me to the Homepage" 3 times, I would like them to bypass the splash page from then on.

I guess I need to set a cookie or something? Can someone outline the basic steps I need to take to accomplish this?
Thank you,
Rich V
reach100 is offline   Reply With Quote
Old 11-13-2012, 09:54 PM   PM User | #2
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 950
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
Cookie would be the best solution. Keep track of the number of times the splash screen has been viewed, once the value is "equal to or greater than" 3, stop showing the splash screen.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Users who have thanked WolfShade for this post:
reach100 (11-13-2012)
Old 11-13-2012, 10:00 PM   PM User | #3
reach100
New Coder

 
Join Date: May 2008
Posts: 34
Thanks: 6
Thanked 0 Times in 0 Posts
reach100 is an unknown quantity at this point
How do I do this?

Can you point me to a resource or help me set this cookie? I don't know how to set a cookie then forward to an alternate url based on the cookie information.

I ca't easily find an explanantion searhing the web so far.
reach100 is offline   Reply With Quote
Old 11-13-2012, 10:08 PM   PM User | #4
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 950
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
Here is a pretty good tutorial on cookies in JavaScript. Read, set, delete, etc.

Basically, I guess the index page would contain the splash screen. Before the splash screen displays, check for the EXISTENCE of the cookie - if there isn't one, write the cookie (name it "splash") and give it a value of 1, then display the splash. If there IS a cookie, check the value - if it's less than 3, display the splash and add 1 to the value of the splash cookie. If it's greater than 3, don't display the splash (I guess a redirect before the splash displays would prevent it from showing.) A simple "IF" conditional can determine whether to show the splash page or redirect to another URL.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

Last edited by WolfShade; 11-13-2012 at 10:10 PM..
WolfShade is offline   Reply With Quote
Old 11-14-2012, 01:21 AM   PM User | #5
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,460
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Note that this is a situation where you need the JavaScript attached in the head of the page rather than at the bottom of the body where most JavaScript goes.

Basically the processing would be

1. set count to zero
2. read the cookie if it exists replace the count with the value from the cookie
3. add 1 to the count
4. save the cookie
5. If the count is greater than 3 then redirect
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is online now   Reply With Quote
Old 11-14-2012, 09:11 AM   PM User | #6
Labrar
New Coder

 
Join Date: Jun 2008
Posts: 61
Thanks: 0
Thanked 12 Times in 12 Posts
Labrar is an unknown quantity at this point
Another question.
Why won't you use PHP instead and use sessions?
What if someone deactivated Javascript?
Labrar is offline   Reply With Quote
Old 11-14-2012, 10:09 PM   PM User | #7
minder
Banned

 
Join Date: Oct 2012
Posts: 81
Thanks: 0
Thanked 4 Times in 4 Posts
minder can only hope to improve
Labrar is pointing you in the right direction. This should be done server side and forget using javascript for this situation. It's not required at all.

Also, do you mean 3 times per session or 3 times over multiple sessions. If you mean 3 times per session then you don't even need cookies (which labrar alluded to), which can also be turned of by the user and so your counter won't work.

If you forget using javascript and do this server side, you can use both a session variable and cookies so that at least you will have a session counter that works in all browsers and if cookies are enabled in the browser, the counter will work over multiple sessions even if javascript is not available.

If you can do something both server and client side, it's always better to do it server side which means it will work all the time and so not have to worry about users whose browsers have javascript unavailable for some reason.

Finally, the code to read and write cookies using PHP is much less than the code required using jabascript.

Last edited by minder; 11-14-2012 at 10:15 PM..
minder is offline   Reply With Quote
Old 11-14-2012, 10:39 PM   PM User | #8
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Just my opinion but I would stick with JavaScript . If someone disables JavaScript then they will encounter many other issues more significant than having to close a splash screen (assuming they still can..). Besides, the page in question already uses a great deal of JavaScript.

Quote:
If you can do something both server and client side, it's always better to do it server side
This is a very sweeping statement.. They are different tools and only overlap in certain specific areas (such as cookies).

I agree that coding cookies is easier in PHP, but not enough to make me chose to use PHP in preference to JS.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS

Last edited by AndrewGSW; 11-14-2012 at 10:43 PM..
AndrewGSW is offline   Reply With Quote
Old 11-14-2012, 10:45 PM   PM User | #9
minder
Banned

 
Join Date: Oct 2012
Posts: 81
Thanks: 0
Thanked 4 Times in 4 Posts
minder can only hope to improve
Quote:
Originally Posted by AndrewGSW View Post
Just my opinion but I would stick with JavaScript .
That's fair enough, but what about the case where cookies are disabled?

By doing this using a server side session you will have a counter that works at least for the session in all cases without needing cookies or javascript. If you limit yourself to javascript, there will be occassions where you won't have a working counter at all.

So I guess it boils down to how critical it is for the op to have a working counter and in what situations for their splash screen.
minder is offline   Reply With Quote
Old 11-14-2012, 11:15 PM   PM User | #10
minder
Banned

 
Join Date: Oct 2012
Posts: 81
Thanks: 0
Thanked 4 Times in 4 Posts
minder can only hope to improve
Quote:
Originally Posted by AndrewGSW View Post
This is a very sweeping statement..
Yes I agree. I suppose I should clarify by saying that if a functionality is critical and must work in all cases and it can be coded both client and server side then it is always better to code it server side because it will work in all cases where coding it client side will most likely result in it not working in all cases.
minder is offline   Reply With Quote
Old 11-14-2012, 11:30 PM   PM User | #11
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,227
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Of course, if the user disables cookies, then the PHP developer must enable cookieless-sessions (they are enabled by default in recent versions of PHP) and, as the PHP manual warns, cookieless sessions are subject to attacks.

Quote:
session.use_only_cookies
specifies whether the module will only use cookies to store the session id on the client side. Enabling this setting prevents attacks involved passing session ids in URLs. This setting was added in PHP 4.3.0. Defaults to 1 (enabled) since PHP 5.3.0.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Old 11-15-2012, 12:53 AM   PM User | #12
minder
Banned

 
Join Date: Oct 2012
Posts: 81
Thanks: 0
Thanked 4 Times in 4 Posts
minder can only hope to improve
Quote:
Originally Posted by Old Pedant View Post
Of course, if the user disables cookies, then the PHP developer must enable cookieless-sessions
Only if you must support cookieless browsers. Whether having the sessionID in the url is a real security risk or not depends on the type of website and the information displayed on the web page.
minder is offline   Reply With Quote
Old 11-15-2012, 05:11 AM   PM User | #13
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,227
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Ummm....you wrote
Code:
By doing this using a server side session you will have a counter that works at least for the session in all cases without needing cookies or javascript.
I was only pointing out that *IF* the user disabled cookies that statement is not true. And then noting the consequences if you are forced to use PHP cookie-less sessions.

Anyway, not disagreeing about whether cookieless sessions implies a problem in all cases. Just noting that it *could*. Clearly not applicable to the simple scenario that is the subject of this thread.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Old 11-15-2012, 08:43 AM   PM User | #14
minder
Banned

 
Join Date: Oct 2012
Posts: 81
Thanks: 0
Thanked 4 Times in 4 Posts
minder can only hope to improve
Quote:
Originally Posted by Old Pedant View Post
I was only pointing out that *IF* the user disabled cookies that statement is not true. And then noting the consequences if you are forced to use PHP cookie-less sessions.
Even in your own statement above you say you can have sessions without a session cookie, so what I said is totally true

You don't need cooikies or javascript if you want a counter just for the browser session.
minder is offline   Reply With Quote
Old 11-15-2012, 11:41 AM   PM User | #15
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,043
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
The OP wanted the splash screen to be shown 3 times only (over multiple sessions). He asked his question in the Javascript forum, and Javascript can very easily do this using a cookie. It is silly to raise the question of Javascript or cookies being disabled. In that case the user just sees the splash screen each time. Note that many people clear out their cookies at frequent intervals, so the cookie that works initially may be deleted hours/days later by the user.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:05 AM.


Advertisement
Log in to turn off these ads.