Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Date last modified

I am very new to script programming, and I was wondering how I would go about having a pop-up window appear for a user if the page they are visiting has been modified since their last visit?

Here is the code that someone has recommend for me to use, but the prompt seems to appear everytime you access the page rather than only if the page was modified since their last visit. Is there something I should change?

Any help would be greatly appreciated

cegmar

(sorry about the length of my post)

<%
'The following script tells the browser not to cache the page and also that the page has expired. Everytime the browser visits this page he is forced to request a new version of the page from the server.
Response.Expires = 60
Response.Expiresabsolute = Now() - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"
%>

<%
'Check the cookie exists, LastVisit is the cookie name.
cookieFound = FALSE
IF Request.Cookies("LastVisit") <> "" THEN
'The cookie exists, read it, and convert it into a VBScript date format
newCookie = CDate(Request.Cookies("LastVisit"))
cookieFound = TRUE
END IF

'Set the next cookie date/time to be the current date/time
Response.Cookies("LastVisit") = CStr(Now)

'response.write(newCookie)
'response.write("
")

Dim strFileName
Dim dtmLastModified
Dim dtmLastModifiedDate
Dim dtmLastModifiedTime

strFileName = Request.ServerVariables("SCRIPT_NAME")
strFileName = Replace(strFileName, "/", "")
strFileName = Server.MapPath(strFileName)

Set objFileSystemObject = Server.CreateObject("Scripting.FileSystemObject")

Set objFile = objFileSystemObject.GetFile(strFileName)
dtmLastModified = objFile.DateLastModified
dtmLastAccessed = objFile.DateLastAccessed
Set objFile = Nothing

Set objFileSystemObject = Nothing

dtmLastModifiedDate = FormatDateTime(dtmLastModified, 1)
dtmLastModifiedTime = FormatDateTime(dtmLastModified, 3)

'Writes the last modified date/time into the specified format
'Response.Write(dtmLastModifiedDate & " " & dtmLastModifiedTime)

'Writes the last modified date/time into the default format
'response.write(dtmLastModified)

'The following calculates the difference newCookie-dtmLastModified and returns the result in seconds "s"
'Dim checkDateDiff
'checkDateDiff = DateDiff("s", dtmLastModified, newCookie)
'response.write("
")
'response.write(checkDateDiff)

IF dtmLastModified >= newCookie THEN
%>



<%
END IF
%>

Comments

  • akdruidakdruid Posts: 22Member
    [b][red]This message was edited by akdruid at 2004-2-3 19:2:59[/red][/b][hr]
    [b][red]This message was edited by akdruid at 2004-2-3 18:58:39[/red][/b][hr]
    The problem is in these lines:[code]
    <% IF dtmLastModified >= newCookie THEN %>



    <% END IF %>[/code]

    You see you can't combine ASP-VBscript with javascript! So what happens is, the javascript code runs every time, without being inside the IF statement!

    Since IIS and ASP doesn't support the MsgBox function you should change these lines to:
    [code]<%IF dtmLastModified >= newCookie THEN %>

    msgbox ("This page has been updated since your last visit.")

    <%END IF %>[/code]

    At least that worked for me... (I have tested your code on my PC and works perefectly ;-))

    akdruid
    cu around

    P.S.: If it doesn't work post again and we'll what's wrong

    [red]Edit:[/red] I forgot to mention that this code works only if the .asp file is modified, not the data that it may hold (e.g from a database)! So if you add new data in the database from which your .asp file and code gets to post, then no message (or pop-up window) will apear...



  • cegmarcegmar Posts: 6Member
    Thanks for your help. I copied the lines that you recommended, but unfortunately it provides me with a script error on the page.


    : [b][red]This message was edited by akdruid at 2004-2-3 19:2:59[/red][/b][hr]
    : [b][red]This message was edited by akdruid at 2004-2-3 18:58:39[/red][/b][hr]
    : The problem is in these lines:[code]
    : <% IF dtmLastModified >= newCookie THEN %>
    :
    :
    :
    : <% END IF %>[/code]
    :
    : You see you can't combine ASP-VBscript with javascript! So what happens is, the javascript code runs every time, without being inside the IF statement!
    :
    : Since IIS and ASP doesn't support the MsgBox function you should change these lines to:
    : [code]<%IF dtmLastModified >= newCookie THEN %>
    :
    : msgbox ("This page has been updated since your last visit.")
    :
    : <%END IF %>[/code]
    :
    : At least that worked for me... (I have tested your code on my PC and works perefectly ;-))
    :
    : akdruid
    : cu around
    :
    : P.S.: If it doesn't work post again and we'll what's wrong
    :
    : [red]Edit:[/red] I forgot to mention that this code works only if the .asp file is modified, not the data that it may hold (e.g from a database)! So if you add new data in the database from which your .asp file and code gets to post, then no message (or pop-up window) will apear...
    :
    :
    :
    :

Sign In or Register to comment.