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-15-2012, 12:02 PM   PM User | #16
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 Philip M View Post
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.
The op didn't specify if it was over multiple sessions or not, hence the questions from Labrar and I.

Obviously Labrar doesn't think it's silly to ask what the op intends to do if javascript or cookies are disabled either. If you do this server side it will work in at least the cases it would work in javascript but if you do it with javascript it will not work in all browsers where it will still work if coded in php, at least for a single session.

So it's a no brainer, if you want to maximise the possible browsers this will work in then do it server side otherwise javascript is fine if you can accept it working in fewer browsers.
minder is offline   Reply With Quote
Old 11-27-2012, 08:29 PM   PM User | #17
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
Thanks for this great discussion. I am the OP and I don't have a problem with cookies being turned off or cleared, that would just give me more exposure to my offer. Currently the splash screen never goes away. I am hoping that someone can give me specific code to use as I am not a programmer, or point me to somewhere I can create it. If someone will do this for a fee I'd be happy to pay. Thaks,
Rich
reach100 is offline   Reply With Quote
Old 11-27-2012, 08:57 PM   PM User | #18
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Here you are:-

<script type = "text/javascript">

var visits = getCookie("visitscounter");
if (!visits) {visits = 0}
visits = Number(visits) + 1;
alert (visits); // for testing
var expdate = new Date ();
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365)); // cookie expires 365 days ahead
setCookie("visitscounter", visits, expdate);

if (visits <= 3) {
// code to show splash screen here
}

function setCookie(isName,isValue,dExpires) {
document.cookie = isName + "=" + isValue + ";expires=" + dExpires.toGMTString() ; // path not specified so cookie only active for this page
}

function getCookie(isName){
cookieStr = document.cookie;
startSlice = cookieStr.indexOf(isName+"=");
if (startSlice == -1) {return false}
endSlice = cookieStr.indexOf(";",startSlice+1)
if (endSlice == -1){endSlice = cookieStr.length}
isData = cookieStr.substring(startSlice,endSlice)
isValue = isData.substring(isData.indexOf("=")+1,isData.length);
return isValue;
}

</script>
__________________

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
Users who have thanked Philip M for this post:
reach100 (11-28-2012)
Old 11-27-2012, 11:16 PM   PM User | #19
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
Thanks, what do I put here?

Thank you for your response. What do I put where is says "// code to show splash screen here." I really appreciate your help.

I did some research and ented this:


if (visits >= 3) {
window.location.href = 'http://www.sealfit.com/hp';
}

Its working, thanks!

Last edited by reach100; 11-28-2012 at 01:00 AM..
reach100 is offline   Reply With Quote
Old 11-28-2012, 07:35 AM   PM User | #20
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by reach100 View Post
Thank you for your response. What do I put where is says "// code to show splash screen here." I really appreciate your help.

I did some research and ented this:


if (visits >= 3) {
window.location.href = 'http://www.sealfit.com/hp';
}

Its working, thanks!
Presumably it should be if(visits >3) {

I understand that you are redrecting to another page (without splash screen) if visits value is more than 3.
__________________

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 09:01 PM.


Advertisement
Log in to turn off these ads.