Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

document.lastModified in a cookie to fire pop-up

Status
Not open for further replies.

bmd218

Programmer
Aug 3, 2004
5
GB
Hi All,

My client wants to fire a pop-up (news_flash.htm) in a 300px square window but he only wants it to appear when the news_flash.htm file has been changed.

How do I incorporate this into a cookie?

Thanks in advance,
Brett
 

Why use cookies?

Given that you're going to have to know if the file has been modified or not anyway, and given that you would pretty much have to use server-side coding for this, why not use the server-side coding to just add the window.open statement to the page?

Hope this helps,
Dan
 
OK, don't really know much about SSI's but I figure the line would be...

<!--#echo var="LAST_MODIFIED" -->

then just add


var page = "news_flash.htm";
var windowprops = "width=300,height=300,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=no";

window.open(page, "", windowprops);


in my html page?

Am I vaguely in the right area?!

Thanks BRPS for the reply btw.
 

The problem is that this:

Code:
<!--#echo var="LAST_MODIFIED" -->

would surely give you the last modified time/date of the current page, not of news_flash.htm, right?

That being the case, you'd have to load news_flash.htm to see if it was modified after you last showed it, but wait - you've got to show it to do that ;o)

Thus my suggestion of a server-side routine instead. I don't know what server you use, so cannot suggest an appropriate technology, but things like PHP, JSP, and ASP should easily be able to get the details of last modified time/date of a file. So you'd get the timestamp, check it against the last-modified time (which you would already know from the last time you updated it), and dynamically write out the window.open (which you've already got in place).

Hope this helps,
Dan
 
Cheers again,

I meant the

<!--#echo var="LAST_MODIFIED" --

would be in news_flash.htm

so I've fixed the problem right?!

Just add the
var page = "news_flash.htm";
var windowprops = "width=300,height=300,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=no";

window.open(page, "", windowprops);

code to my index.shtml file and away we go?

Tell me I've cracked it!!!
 

bmd218 said:
I meant the

<!--#echo var="LAST_MODIFIED" --

would be in news_flash.htm

I know - but to pick up on it, you'd need to display the file - and if you're displaying the file anyway, then you've negated the need to display it only if it has changed - which was your initial requirement, right?

Maybe I've totally misunderstood your requirements. If that's the case, can you try and explain them again?

Dan
 
OK, maybe we have some wires crossed!!!

Basically, what would happen is if you first visited the site at 10am the pop-up (containing news_flash.htm) would appear.

If you visited the site at 11am and news_flash.htm hasn't changed the pop-up would not appear.

If you visited the site at 2pm and news_flash.htm had changed the pop-up would fire.

Now, along with the SSI directive in news_flash.htm, would I also need to use a cookie to compare the dates, times and therefore versions of the news_flash.htm on the server?

I presume it can't be as easy as just adding the window.open script listed above.
 

bmd218 said:
Now, along with the SSI directive in news_flash.htm, would I also need to use a cookie to compare the dates, times and therefore versions of the news_flash.htm on the server?

OK - I think this is the crux of the crossed wires ;o)

You cannot use a cookie to compare dates. You can use a cookie to store the last modified date of the news_flash.htm page no problem - as long as you have that date (which you would, initially).

The problem then comes with the next load of the page (11am in your example). How, without loading the news_flash.htm page, would you get its last-modifed date to test against the value held in the cookie?

This is what I'm saying - to do this, you'd either need to load the page (defeating the whole script), or use server-side code.

Dan
 
So the

<!--#echo var="LAST_MODIFIED" -->

directive that sits on news_flash.htm would do everything I need.

How would it work with every page load of index.shtml?

Would the

var page = "news_flash.htm";
var windowprops = "width=300,height=300,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=no";

window.open(page, "", windowprops);

code prevents repeat pop-ups if the file has not been modified?
 

bnd218 said:
So the

<!--#echo var="LAST_MODIFIED" -->

directive that sits on news_flash.htm would do everything I need

No - it would not do what you need. It would only do half of what you need. You still need to be able to get the last modified time of the news_flash.htm file without actually loading it to be able to have a date/time to compare against that in the cookie.

Therefore, you would need to deliver this to your index page.

I'm sure I cannot make myself any clearer, so maybe someone else would be better suited to helping you understand the big flaw in your idea?

Dan
 
And to add to the fray... you will need to store the fact that *for a specific user* the news_flash page has been shown. Going back to your original description... I would investigate the use of client-side cookies. See the following...

Scenario:
I visit the site, and the first page checks to see if I have viewed the news_flash page (by checking to see if I have a cookie set on my browser).

If there is no cookie, then display the news_flash... and set the cookie value to the "last modified date" of the news_flash file.

If there is a cookie (the user is revisiting the site) then we need to get the value of the cookie and compare that against the last modified date of the news_flash file. If the two are "out of synch" then you display the news_flash file and set the cookie (as in the previous paragraph). If they are "in sync" then do not display the news_flash file and do not set and cookie.

How to get that last modified date:
The news_flash file needs to be on the same server as the rest of the web site. You can then query the details for the file server-side using various methods (in JSP I instantiate a file object, supply a path to the file and then attempt to access the file... if the file exists I can then get/set information about it).

You might then pass the "last modified date" into the page and assign it to a Javascript variable which would then allow you to trigger a Javascript solution that checks that client-side cookie value.

It's not as simple as it sounds... but there are plenty of examples online for multiple different server-side scripting environments to query file details and to set/get cookie values.

Hope this gets you on the right path...
Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top