Guest javasun Posted December 7, 2005 Share Posted December 7, 2005 (edited) Hi all, I'm having some problem by trying to find a javascript for (Auto Expire Content) which will work on all modern browsers. I have here one script: ////////////////////////////////////////////////////////////////////////////////////////////<!-- Begin// Set the dates belowvar goLiveDate = "20030613";var expireDate = "20051003";var expireYear = expireDate.substring(0,4)var expireMonth = expireDate.slice(4,-2)var expireDay = expireDate.slice(6)var liveYear = goLiveDate.substring(0,4)var liveMonth = goLiveDate.slice(4,-2)var liveDay = goLiveDate.slice(6)var nowDate = new Date();var day = nowDate.getUTCDate();var month = nowDate.getUTCMonth();var month1 = month + 1; if (month1 < 10) { month1 = "0" + month1; } if (day < 10) { day = "0" + day; }var year = nowDate.getYear();var GMTdate = year + "" + month1 + "" + dayif ((GMTdate < expireDate) && (GMTdate >= goLiveDate)){// Insert the text you want displayed belowdocument.write("<div align='center'><b>This content appeared on " + liveMonth + "/" + liveDay + "/" + liveYear + "<br>and will disappear on " + expireMonth + "/" + expireDay + "/" + expireYear +".</b></div>")}// End -->/////////////////////////////////////////////////////////////////////but how can I get it to work in real time with SSI or PHP for example, because this is working depending on your PC time. I have one script here for displaying the real time with Javascript and SSI or PHP:////////////////////////////////////////////////////////////////////////////////////\\<script type="text/javascript">var weekdaystxt=["Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat"]function showLocalTime(container, servermode, offsetMinutes, displayversion){if (!document.getElementById || !document.getElementById(container)) returnthis.container=document.getElementById(container)this.displayversion=displayversionvar servertimestring=(servermode=="server-php")? '<? print date("F d, Y H:i:s", time())?>' : '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->'this.localtime=this.serverdate=new Date(servertimestring)this.localtime.setTime(this.serverdate.getTime()+offsetMinutes*60*1000) //add user offset to server timethis.updateTime()this.updateContainer()}showLocalTime.prototype.updateTime=function(){var thisobj=thisthis.localtime.setSeconds(this.localtime.getSeconds()+1)setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second}showLocalTime.prototype.updateContainer=function(){var thisobj=thisif (this.displayversion=="long")this.container.innerHTML=this.localtime.toLocaleString()else{var hour=this.localtime.getHours()var minutes=this.localtime.getMinutes()var seconds=this.localtime.getSeconds()var ampm=(hour>=12)? "" : ""var currentdate=this.localtime.getDate()+"-"+(this.localtime.getMonth()+1)+"-"+this.localtime.getFullYear()var dayofweek=weekdaystxt[this.localtime.getDay()]this.container.innerHTML=formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+" ("+currentdate+" - "+dayofweek+")"}setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second}function formatField(num, isHour){if (typeof isHour!="undefined"){ //if this is the hour fieldvar hour=(num>24)? num-24 : numreturn (hour==0)? 24 : hour}return (num<=9)? "0"+num : num//if this is minute or sec field}\\</script>then in <BODY><span id="timecontainer"></span><script type="text/javascript">new showLocalTime("timecontainer", "server-php", 0, "short")</script>////////////////////////////////////////////////////////////////////////////// .... can somebody help me please, is there any way I can mix this two scripts, or if you know some other script where the content will auto expire in the set date and time mm/dd/yyy - h:mThank you!edit: wrapped script in codebox to display better - skemcin Edited December 7, 2005 by Skemcin Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now