/    Sign up×
Community /Pin to ProfileBookmark

document.lastModified in a cookie

Hi All,

I’m trying to write a cookie that pops-up a window but only when it’s been updated.

Is there a way to do this using document.lastModified and get it to work as I can’t think of anything!?

Any help would be appreciated.

Brett.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@JonaAug 02.2004 — [font=trebuchet ms]I'm having difficulty understanding your problem. You want a window to popup, each time the document is modified?[/font]
Copy linkTweet thisAlerts:
@bmdauthorAug 02.2004 — [i]Originally posted by Jona [/i]

[B][font=trebuchet ms]I'm having difficulty understanding your problem. You want a window to popup, each time the document is modified?[/font] [/B][/QUOTE]


Basically yes,

The pop-up page will be a news flash page that the client only wants to pop-up whenever the file has been changed to reflect new news.
Copy linkTweet thisAlerts:
@JonaAug 02.2004 — [font=trebuchet ms]Is this what you're after? [url=http://66.170.214.217/jona/research/javascript/bdm/modified.html]Example[/url].[/font]

<i>
</i>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/xhtml1-strict.dtd"&gt;
&lt;html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;title&gt;Document modification notification example&lt;/title&gt;
&lt;script type="text/javascript"&gt;
function getCVal(cName){
if(document.cookie.indexOf(cName) == 1){
return 0;
} else {
var cData = document.cookie.split("=")[1];
cData = cData.split(";")[0];
return cData;
}
}
window.onload = function(){
var d = new Date();
var cD = d.toGMTString();
var nD = document.lastModified;
if (getCVal("lVisit") &gt; nD) {
window.open("updates.html","child","width=400,height=400");
}
document.cookie="lVisit="+cD+"; expires=Monday, 04-Apr-2006 05:00:00 GMT";
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;JavaScript Cookie Exapmle&lt;/h1&gt;
&lt;p&gt;You must have JavaScript and cookies enabled to view this example.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@bmdauthorAug 03.2004 — Hi Jona,

Thanks for the reply.

I can't access your example but what I'm after is a pop-up that fires from the home page the first time you visit the site. The pop-up only then appears once the .htm file in the pop-up has been updated.
Copy linkTweet thisAlerts:
@JonaAug 03.2004 — [font=trebuchet ms]Sorry that's on a personal server and only works when I'm online.

What I gave, though, is not exactly what you are now asking, so it's not important. If I understand correctly, you want a popup to appear if there is no cookie, and once the popup appears, a cookie is set to the last modified date of the file. Next time they visit the site, if the cookie exists and is not equal to the last modified date of the popup, show the popup, otherwise don't show it. Correct? The only way you could do this, would be to open the popup, and close it automatically if the cookie date and last modified date are equal, because you cannot get the last modified date of the popup from the parent window.[/font]
×

Success!

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