/    Sign up×
Community /Pin to ProfileBookmark

Cannot Figure This Out

Hello,
I am by no means a person who is remotely proficient in javascript. I’ll do my best to stay within what is acceptable for a post here.

We purchased a javascript counter, and yes I did contact the author of the code and he has helped some, but I have not been able to get a response from him for about 2 weeks, so I am kind of at a loss for what to try.

We, the company I work for, have a webpage up that has daily specials that change every 24hrs. Here is the link: [url]http://www.grimco.com/InfoPages/daily_deal/daily_deal.aspx[/url]

Every night at midnight central time the div “any_html” updates to show new content, etc. That part works just fine. As you can see on the page, there is a counter that counts down the time left on the special, which also works just fine. The issue we’re having is that if someone viewing the page either has the incorrect date, or changes their date on their computer they can see what specials are going to be coming up. I’m trying to find a way to stop them from being able to do that (if that is possible). I thought about just updating the page everyday before I leave with new code, but figure there should be an easier way. Here is the code that we are using on that page

[CODE]<script type=”text/javascript”>

var myCounter = null;
var timerId = null;
var destTime = null;

var rotatedImages = [
{ html: ‘<div style=”background-image:url(deal_statement.png); height:388px; width:900px”>&nbsp;<div style=”width:626px; height:239px; margin:95px 0px 0px 255px”><a href=”http://twitter.com/#!/GrimcoDailyDeal”><img src=”deal_statement_1.png” border=”0″ alt=”Deal of the Day”/></a></div></div>’, dateFrom: new Date(2011, 07, 02, 24, 0, 0), dateTo: new Date(2011, 07, 07, 24, 0, 0) },
{ html: ‘<div style=”background-image:url(deal1_background.png); height:388px; width:900px”>&nbsp;<div style=”width:626px; height:239px; margin:95px 0px 0px 255px”><a href=”../../Products.aspx?cid=0003&pid=00022″><img src=”deal1.png” border=”0″ alt=”Deal of the Day”/></a></div></div>’, dateFrom: new Date(2011, 07, 07, 24, 0, 0), dateTo: new Date(2011, 07, 08, 24, 0, 0) },];
function loadCounter() {
myCounter = [
new Counter(“my_counter_1”,
{digitsNumber: 2,
direction: Counter.ScrollDirection.Downwards,
characterSet: Counter.DefaultCharacterSets.numericUp,
charsImageUrl: “images/numeric_up_redbg5.png”,
markerImageUrl: “marker.png”,
extraClassName: {left: “ex1_left”,
right: “ex1_right”,
inner: “ex1_inner”}}),
new Counter(“my_counter_2”,
{digitsNumber: 2,
direction: Counter.ScrollDirection.Downwards,
characterSet: Counter.DefaultCharacterSets.numericUp,
charsImageUrl: “images/numeric_up_redbg5.png”,
markerImageUrl: “marker.png”,
extraClassName: {left: “ex1_left”,
right: “ex1_right”,
inner: “ex1_inner”}}),
new Counter(“my_counter_3”,
{digitsNumber: 2,
direction: Counter.ScrollDirection.Downwards,
characterSet: Counter.DefaultCharacterSets.numericUp,
charsImageUrl: “images/numeric_up_redbg5.png”,
markerImageUrl: “marker.png”,
extraClassName: {left: “ex1_left”,
right: “ex1_right”,
inner: “ex1_inner”}})];

timerId = window.setInterval(function () {

var i = 0;
var now = new Date();

if (destTime == null){
for (i = 0; i < rotatedImages.length; i++)
if (now >= rotatedImages[i].dateFrom && now < rotatedImages[i].dateTo){
destTime = rotatedImages[i].dateTo;
document.getElementById(‘any_html’).innerHTML = rotatedImages[i].html;
break;
}
}

var diff = Math.floor((destTime – now) / 1000);

if (diff <= 0)
destTime = null;

myCounter[0].setValue(Math.floor(diff / 3600 % 99), 800);
myCounter[1].setValue(Math.floor(diff / 60 % 60), 800);
myCounter[2].setValue(diff % 60, 800);
}, 1000);
}

loadCounter();
</script>[/CODE]

This code all works, I just need to figure out how to stop visitors from updating their date/time to see future specials.

I had a friend, who knows a little bit about javascript suggest adding this code:

[CODE]now.setTime(<% Response.Write( ((long)(DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds)).ToString() ); %>);
[/CODE]

under the line that reads:

[CODE]var now = new Date();
[/CODE]

I did try that but when I do I get a syntax error and the page no longer works, so I took it out. Sorry if this is way too long but I tried to be as thorough as possible.

Thank you for any guidance you can give.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@p_phreshAug 31.2011 — Due to the nature of javascript, you cannot prevent them from changing the date/time on their computer.

And because Javascript runs on the user's computer after its left the server, it is going to get its date and time from the computer it's running from.

The piece of code you got from your friend takes the date and time from the server using ASP before it serves the javascript, so the time will be set beforehand.

I'm not proficient in ASP so you may want to ask someone in the ASP forum if that bit is correct.

take a look at this page to see how to set the date based on the piece of code you've got now:

http://www.w3schools.com/jsref/jsref_obj_date.asp

you can alert the string to see what its producing and try to apply it to the info above.
[code=php]alert("<&#37; Response.Write( ((long)(DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds)).ToString() ); %>");[/code]


keep in mind this won't prevent everyone from seeing what the next special is. The date could still be changed by someone using greasemonkey and setting the date afterwards... it's less likely to happen and will thwart most average users. The best way to handle this sort of thing may be to use ASP completely for the controlling how the content will be displayed via the date.
×

Success!

Help @Borgard 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.23,
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,
)...