bezorg de laatste berichten direct op de desktop
Welkom, Gast
Alstublieft Inloggen of Registreren.    Wachtwoord verloren?

Javascript clock versus asp
(1 bezoeker) (1) Gast
Ga naar onderkantPagina: 12
TOPIC: Javascript clock versus asp
#2964
Javascript clock versus asp 5 Jaren, 11 Maanden geleden Karma: 0
Hello iedereen,

:?: ik heb een vraagje: ik heb op mijn site een top frame en een main frame.
Dit topframe wijzigt niet en in het main frame komen de nieuwe pages.
Nu heb ik de java clock gebruikt van hier op de site om een uur aanduiding te geven. Deze wordt echter niet gerefreshed doordat het topframe nooit opnieuw wordt geladen.
Mijn [url=http://www.belgianpolymergroup.be:28u16x25]huidige site[/url:28u16x25]
Kan ik dat ergens ingeven?

Ik heb ook nog een script gevonden in asp of php dat dit wel doet, alleen weet ik niet echt hoe het te gebruiken, want er is een serverside code en een user side code.
[quote:28u16x25]<%@ LANGUAGE="JavaScript" %>
<%
/*** Clock -- beginning of server-side support code
by Andrew Shearer, <!-- m --><a class="postlink" href="http://www.shearersoftware.com/">http://www.shearersoftware.com/</a><!-- m -->
v2.1-ASP, 2002-10-12. For updates and explanations, see
&lt;http://www.shearersoftware.com/software/web-tools/clock/&gt;. ***/

/* Prevent this page from being cached (though some browsers still
cache the page anyway, which is why we use cookies). This is
only important if the cookie is deleted while the page is still
cached (and for ancient browsers that don't know about Cache-Control).
If that's not an issue, you may be able to get away with
"Cache-Control: private" instead. */
Response.AddHeader("Pragma", "no-cache");

/* Grab the current server time. */
var gDate = new Date();
/* Are the seconds shown by default? When changing this, also change the
JavaScript client code's definition of clockShowsSeconds below to match. */
var clockShowsSeconds = false;

function getServerDateItems() {
return gDate.getFullYear()+","+gDate.getMonth()+","+gDate.getDate()+","
+gDate.getHours()+","+gDate.getMinutes()+","+gDate.getSeconds();
}

function clockDateString(inDate) {
return ["Sunday, ","Monday, ","Tuesday, ","Wednesday, ",
"Thursday, ","Friday, ","Saturday, "][inDate.getDay()]
+ ["January ","February ","March ","April ","May ","June ",
"July ", "August ","September ","October ","November ","December "]
[inDate.getMonth()]
+ inDate.getDate() + ", " + inDate.getFullYear();
}

function clockTimeString(inHours, inMinutes, inSeconds) {
return (inHours == 0 ? "12" : (inHours &lt;= 12 ? inHours : inHours - 12))
+ (inMinutes &lt; 10 ? ":0" : ":") + inMinutes
+ (clockShowsSeconds ? ((inSeconds &lt; 10 ? ":0" : ":") + inSeconds) : "")
+ (inHours &lt; 12 ? " AM" : " PM");
}
/*** Clock -- end of server-side support code ***/
%&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Clock&lt;/title&gt;
&lt;meta name="template" content="none"&gt;
&lt;script language="JavaScript" type="text/javascript"&gt;
&lt;!--
/* set up variables used to init clock in BODY's onLoad handler;
should be done as early as possible */
var clockLocalStartTime = new Date();
var clockServerStartTime = new Date(&lt;%=getServerDateItems()%&gt;);

/* stub functions for older browsers;
will be overridden by next JavaScript1.2 block */
function clockInit() {
}
//--&gt;
&lt;/script&gt;
&lt;script language="JavaScript1.2" type="text/javascript"&gt;
&lt;!--
/*** simpleFindObj, by Andrew Shearer

Efficiently finds an object by name/id, using whichever of the IE,
classic Netscape, or Netscape 6/W3C DOM methods is available.
The optional inLayer argument helps Netscape 4 find objects in
the named layer or floating DIV. */
function simpleFindObj(name, inLayer) {
return document[name] || (document.all &amp;&amp; document.all[name])
|| (document.getElementById &amp;&amp; document.getElementById(name))
|| (document.layers &amp;&amp; inLayer &amp;&amp; document.layers[inLayer].document[name]);
}

/*** Beginning of Clock 2.0, by Andrew Shearer
See: <!-- m --><a class="postlink" href="http://www.shearersoftware.com/software/web-tools/clock/">http://www.shearersoftware.com/software ... ols/clock/</a><!-- m -->
Redistribution is permitted with the above notice intact.

Client-side clock, based on computed time differential between browser &amp;
server. The server time is inserted by server-side JavaScript, and local
time is subtracted from it by client-side JavaScript while the page is
loading.

Cookies: The local and remote times are saved in cookies named
localClock and remoteClock, so that when the page is loaded from local
cache (e.g. by the Back button) the clock will know that the embedded
server time is stale compared to the local time, since it already
matches its cookie. It can then base the calculations on both cookies,
without reloading the page from the server. (IE 4 &amp; 5 for Windows didn't
respect Response.Expires = 0, so if cookies weren't used, the clock
would be wrong after going to another page then clicking Back. Netscape
&amp; Mac IE were OK.)

Every so often (by default, one hour) the clock will reload the page, to
make sure the clock is in sync (as well as to update the rest of the
page content).

Compatibility: IE 4.x and 5.0, Netscape 4.x and 6.0, Mozilla 1.0. Mac &amp; Windows.

History: 1.0 5/9/2000 GIF-image digits
2.0 6/29/2000 Uses text DIV layers (so 4.0 browsers req'd), &amp;
cookies to work around Win IE stale-time bug
2.1 10/12/2002 Noted Mozilla 1.0 compatibility; released PHP version.
*/
var clockIncrementMillis = 60000;
var localTime;
var clockOffset;
var clockExpirationLocal;
var clockShowsSeconds = false;
var clockTimerID = null;

function clockInit(localDateObject, serverDateObject)
{
var origRemoteClock = parseInt(clockGetCookieData("remoteClock"));
var origLocalClock = parseInt(clockGetCookieData("localClock"));
var newRemoteClock = serverDateObject.getTime();
// May be stale (WinIE); will check against cookie later
// Can't use the millisec. ctor here because of client inconsistencies.
var newLocalClock = localDateObject.getTime();
var maxClockAge = 60 * 60 * 1000; // get new time from server every 1hr

if (newRemoteClock != origRemoteClock) {
// new clocks are up-to-date (newer than any cookies)
document.cookie = "remoteClock=" + newRemoteClock;
document.cookie = "localClock=" + newLocalClock;
clockOffset = newRemoteClock - newLocalClock;
clockExpirationLocal = newLocalClock + maxClockAge;
localTime = newLocalClock; // to keep clockUpdate() happy
}
else if (origLocalClock != origLocalClock) {
// error; localClock cookie is invalid (parsed as NaN)
clockOffset = null;
clockExpirationLocal = null;
}
else {
// fall back to clocks in cookies
clockOffset = origRemoteClock - origLocalClock;
clockExpirationLocal = origLocalClock + maxClockAge;
localTime = origLocalClock;
// so clockUpdate() will reload if newLocalClock
// is earlier (clock was reset)
}
/* Reload page at server midnight to display the new date,
by expiring the clock then */
var nextDayLocal = (new Date(serverDateObject.getFullYear(),
serverDateObject.getMonth(),
serverDateObject.getDate() + 1)).getTime() - clockOffset;
if (nextDayLocal &lt; clockExpirationLocal) {
clockExpirationLocal = nextDayLocal;
}
}

function clockOnLoad()
{
clockUpdate();
}

function clockOnUnload() {
clockClearTimeout();
}

function clockClearTimeout() {
if (clockTimerID) {
clearTimeout(clockTimerID);
clockTimerID = null;
}
}

function clockToggleSeconds()
{
clockClearTimeout();
if (clockShowsSeconds) {
clockShowsSeconds = false;
clockIncrementMillis = 60000;
}
else {
clockShowsSeconds = true;
clockIncrementMillis = 1000;
}
clockUpdate();
}

function clockTimeString(inHours, inMinutes, inSeconds) {
return inHours == null ? "-:--" : ((inHours == 0
? "12" : (inHours &lt;= 12 ? inHours : inHours - 12))
+ (inMinutes &lt; 10 ? ":0" : ":") + inMinutes
+ (clockShowsSeconds
? ((inSeconds &lt; 10 ? ":0" : ":") + inSeconds) : "")
+ (inHours &lt; 12 ? " AM" : " PM"));
}

function clockDisplayTime(inHours, inMinutes, inSeconds) {

clockWriteToDiv("ClockTime", clockTimeString(inHours, inMinutes, inSeconds));
}

function clockWriteToDiv(divName, newValue) // APS 6/29/00
{
var divObject = simpleFindObj(divName);
newValue = '&lt;p&gt;' + newValue + '&lt;' + '/p&gt;';
if (divObject &amp;&amp; divObject.innerHTML) {
divObject.innerHTML = newValue;
}
else if (divObject &amp;&amp; divObject.document) {
divObject.document.writeln(newValue);
divObject.document.close();
}
// else divObject wasn't found; it's only a clock, so don't bother complaining
}

function clockGetCookieData(label) {
/* find the value of the specified cookie in the document's
semicolon-delimited collection. For IE Win98 compatibility, search
from the end of the string (to find most specific host/path) and
don't require "=" between cookie name &amp; empty cookie values. Returns
null if cookie not found. One remaining problem: Under IE 5 [Win98],
setting a cookie with no equals sign creates a cookie with no name,
just data, which is indistinguishable from a cookie with that name
but no data but can't be overwritten by any cookie with an equals
sign. */
var c = document.cookie;
if (c) {
var labelLen = label.length, cEnd = c.length;
while (cEnd &gt; 0) {
var cStart = c.lastIndexOf(';',cEnd-1) + 1;
/* bug fix to Danny Goodman's code: calculate cEnd, to
prevent walking the string char-by-char &amp; finding cookie
labels that contained the desired label as suffixes */
// skip leading spaces
while (cStart &lt; cEnd &amp;&amp; c.charAt(cStart)==" ") cStart++;
if (cStart + labelLen &lt;= cEnd &amp;&amp; c.substr(cStart,labelLen) == label) {
if (cStart + labelLen == cEnd) {
return ""; // empty cookie value, no "="
}
else if (c.charAt(cStart+labelLen) == "=") {
// has "=" after label
return unescape(c.substring(cStart + labelLen + 1,cEnd));
}
}
cEnd = cStart - 1; // skip semicolon
}
}
return null;
}

/* Called regularly to update the clock display as well as onLoad (user
may have clicked the Back button to arrive here, so the clock would need
an immediate update) */
function clockUpdate()
{
var lastLocalTime = localTime;
localTime = (new Date()).getTime();

/* Sanity-check the diff. in local time between successive calls;
reload if user has reset system clock */
if (clockOffset == null) {
clockDisplayTime(null, null, null);
}
else if (localTime &lt; lastLocalTime || clockExpirationLocal &lt; localTime) {
/* Clock expired, or time appeared to go backward (user reset
the clock). Reset cookies to prevent infinite reload loop if
server doesn't give a new time. */
document.cookie = 'remoteClock=-';
document.cookie = 'localClock=-';
location.reload(); // will refresh time values in cookies
}
else {
// Compute what time would be on server
var serverTime = new Date(localTime + clockOffset);
clockDisplayTime(serverTime.getHours(), serverTime.getMinutes(),
serverTime.getSeconds());

// Reschedule this func to run on next even clockIncrementMillis boundary
clockTimerID = setTimeout("clockUpdate()",
clockIncrementMillis - (serverTime.getTime() % clockIncrementMillis));
}
}

/*** End of Clock ***/
//--&gt;
&lt;/script&gt;
&lt;/head&gt;

&lt;body bgcolor="#FFFFFF"
onload="clockInit(clockLocalStartTime, clockServerStartTime);clockOnLoad();"
onunload="clockOnUnload()"&gt;

&lt;div id="ClockTime" style="position: absolute; left: 406px; top: 28px;
width: 200px; height: 20px; z-index: 11; cursor: pointer"
onclick="clockToggleSeconds()"&gt;
&lt;p&gt;&lt;%=clockTimeString(gDate.getHours(), gDate.getMinutes(), gDate.getSeconds())%&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div id="ClockBkgnd" style="position: absolute; left: 406px; top: 28px;
width: 200px; z-index: 10"&gt;
&lt;p&gt; &lt;br&gt;
&lt;%=clockDateString(gDate)%&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&lt;i&gt;Click on the time to show or hide seconds.&lt;/i&gt;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
[/quote:28u16x25]
Nu ik denk dat je het script moet saven als een clock.asp, maar wat dan met die server code?
Ik zoiets gezien op [url=http&#58;//www&#46;hattrick&#46;org:28u16x25]deze site[/url:28u16x25] onderaan staat de clock in een .asp file in een apart frame.

Alvast op voorhand bedankt!!

:wink:
Nico
tozziewozz
Nieuwe Gebruiker
Berichten: 0
graphgraph
Gebruiker offline Klik hier om het gebruikersprofiel van deze gebruiker te zien
De Administrator heeft publieke schrijf toegang geblokkeerd.
 
#2965
5 Jaren, 11 Maanden geleden Karma: 0
Als ik in het bestand <!-- m --><a class="postlink" href="www.belgianpolymergroup.be/top.html"...p.html</a><!-- m --> kijk, dan zie ik niets van dat asp scrippie... :?
Deze staat er wel:
[code:30p3vebd]&lt;script type=&quot;text/javascript&quot;&gt;
&lt;!--
var tijd_datum = new Date&#40;&#41;;
var dag = tijd_datum&#46;getDay&#40;&#41;; //dag in woorden
var dag2 = tijd_datum&#46;getDate&#40;&#41;; // dag in getal
var maand = tijd_datum&#46;getMonth&#40;&#41;; // +1 want js begint bij 0 te tellen
var jaar = tijd_datum&#46;getFullYear&#40;&#41;;

var uur = tijd_datum&#46;getHours&#40;&#41;;
var minuten = tijd_datum&#46;getMinutes&#40;&#41;;
var seconden = tijd_datum&#46;getSeconds&#40;&#41;;

var maandarray = new Array&#40;'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'&#41;;
var dagarray = new Array&#40;'Sunday','Monday','Thuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'&#41;;
document&#46;write&#40;dagarray&#91;dag&#93;+&quot; &quot;+dag2+&quot; &quot;+maandarray&#91;maand&#93;+&quot; &quot;+jaar+&quot; &quot;+uur+&quot;&#58;&quot;+minuten+&quot;&#58;&quot;+seconden&#41;;
//--&gt;
&lt;/script&gt;[/code:30p3vebd]
Dat is die van <!-- m --><a class="postlink" href="www.wvdwebdesign.be/?load=js_tijd"&...s_tijd</a><!-- m --> toch?
Die is ook helemaal niet bedoeld om zich steeds te verversen!
Rik
Moderator
Berichten: 28
graphgraph
Gebruiker offline Klik hier om het gebruikersprofiel van deze gebruiker te zien
De Administrator heeft publieke schrijf toegang geblokkeerd.
 
#2966
5 Jaren, 11 Maanden geleden Karma: 0
Ik heb inderdaad nu de java clock van webdesign staat,

maar ik zou graag een clock krijgen die zich ververst zodanig dat de tijd altijd correct is.

Daarom wilde ik bovenstaand script gebruiken, maar ik krijg het niet in gang, want ik weet niet goed hoe te beginnen
tozziewozz
Nieuwe Gebruiker
Berichten: 0
graphgraph
Gebruiker offline Klik hier om het gebruikersprofiel van deze gebruiker te zien
De Administrator heeft publieke schrijf toegang geblokkeerd.
 
#2969
5 Jaren, 11 Maanden geleden Karma: 0
Als je dit als top.html neemt, dan werkt je klok:
[code:1t1cvmby]&lt;html&gt;
&lt;head&gt;
&lt;title&gt;logo&lt;/title&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;&gt;
&lt;link href=&quot;bpg_b&#46;css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
&lt;!--
function tijd_datum&#40;&#41;
&#123;
datum&#40;&#41;;
tijd&#40;&#41;;
&#125;

function datum&#40;&#41;
&#123;
var tijd_datum = new Date&#40;&#41;;
var dag = tijd_datum&#46;getDay&#40;&#41;; //dag in woorden
var dag2 = tijd_datum&#46;getDate&#40;&#41;; // dag in getal
var maand = tijd_datum&#46;getMonth&#40;&#41;; // +1 want js begint bij 0 te tellen
var jaar = tijd_datum&#46;getFullYear&#40;&#41;;

var maandarray = new Array&#40;'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'&#41;;
var dagarray = new Array&#40;'Sunday','Monday','Thuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'&#41;;

document&#46;getElementById&#40;'datum'&#41;&#46;innerText = dagarray&#91;dag&#93;+&quot; &quot;+dag2+&quot; &quot;+maandarray&#91;maand&#93;+&quot; &quot;+jaar;
&#125;

function tijd&#40;&#41;
&#123;
var tijd_datum = new Date&#40;&#41;;
var uur = tijd_datum&#46;getHours&#40;&#41;;
var minuten = tijd_datum&#46;getMinutes&#40;&#41;;
var seconden = tijd_datum&#46;getSeconds&#40;&#41;;
uur = uur &lt; 10 ? '0' + uur &#58; uur;
minuten = minuten &lt; 10 ? '0' + minuten &#58; minuten;
seconden = seconden &lt; 10 ? '0' + seconden &#58; seconden;

document&#46;getElementById&#40;'tijd'&#41;&#46;innerText = uur+&quot;&#58;&quot;+minuten+&quot;&#58;&quot;+seconden;

setTimeout&#40;'tijd&#40;&#41;', 1000&#41;;
&#125;
//--&gt;
&lt;/script&gt;

&lt;/head&gt;

&lt;body onload=&quot;tijd_datum&#40;&#41;&quot;&gt;
&lt;div align=&quot;center&quot;&gt;
&lt;table width=&quot;100%&quot; border=&quot;0&quot;&gt;
&lt;tr&gt;

&lt;td width=&quot;20%&quot;&gt;
&lt;p&gt;&lt;img src=&quot;images/background/BPG_logo_KLEIN&#46;gif&quot; width=&quot;170&quot; height=&quot;82&quot; align=&quot;left&quot; border=&quot;0&quot; name=&quot;bpgklein&quot; usemap=&quot;#bpgkleinMapMapMap2&quot;&gt;

&lt;map name=&quot;bpgkleinMapMapMap2&quot;&gt;
&lt;area shape=&quot;rect&quot; coords=&quot;-36,10,202,110&quot; href=&quot;index&#46;html&quot; target=&quot;_blank&quot; alt=&quot;HOME&#58; Welcome to the BPG Website&quot; title=&quot;Welcome to the Belgian Polymer Group Website&quot;&gt;
&lt;/map&gt;
&lt;map name=&quot;bpgkleinMapMapMap&quot;&gt;
&lt;area shape=&quot;rect&quot; coords=&quot;-38,0,200,100&quot; href=&quot;index&#46;html&quot; target=&quot;_blank&quot; alt=&quot;welcome to BPG&quot; title=&quot;Welcome to BPG&quot;&gt;
&lt;/map&gt;
&lt;/p&gt;
&lt;/td&gt;
&lt;td width=&quot;65%&quot;&gt;&lt;img src=&quot;images/background/BPG_logo_GROOT&#46;gif&quot; width=&quot;467&quot; height=&quot;76&quot; align=&quot;absmiddle&quot; alt=&quot;BPG logo&quot;&gt;&lt;/td&gt;

&lt;td width=&quot;15%&quot;&gt;&lt;H3&gt;&#91;&lt;a href=&quot;news&#46;html&quot; target=&quot;main&quot; class=&quot;style1&quot;&gt;NEWS&lt;/a&gt;&#93;&lt;/H3&gt;
&lt;p&gt;
&lt;span id=&quot;datum&quot;&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span id=&quot;tijd&quot;&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;


&lt;/body&gt;
&lt;/html&gt;
[/code:1t1cvmby]
Met dat asp script kon je nog instellen of je wel of geen secondes wilt weergeven. Als je wilt script ik dat er nog wel tussen...

En die haalde de tijd van de server op, zodat de klok gelijk liep met die van de server. Javascript gebruikt de tijd van de gebruiker. Maar ik denk dat iemand het juist irritant vindt als er een andere tijd dan die op zijn pc te zien is. En anders zou je met tijdzones enzo gaan werken. Dat lijkt me niet echt nodig.
Rik
Moderator
Berichten: 28
graphgraph
Gebruiker offline Klik hier om het gebruikersprofiel van deze gebruiker te zien
De Administrator heeft publieke schrijf toegang geblokkeerd.
 
#2971
5 Jaren, 11 Maanden geleden Karma: 0
!!SUPER!!

Hartelijk bedankt zeg
tozziewozz
Nieuwe Gebruiker
Berichten: 0
graphgraph
Gebruiker offline Klik hier om het gebruikersprofiel van deze gebruiker te zien
De Administrator heeft publieke schrijf toegang geblokkeerd.
 
#2972
5 Jaren, 11 Maanden geleden Karma: 0
Toch nog een klein vraagje , om het zelf goed te begrijpen:

Is dat met die

[quote:3b4gekfv]
setTimeout('tijd()', 1000);
}
[/quote:3b4gekfv]

Dat je de clock opfrist?

Alleszins, het werkt perfect!!

Nog eens bedankt
Groetjes,
Nico
tozziewozz
Nieuwe Gebruiker
Berichten: 0
graphgraph
Gebruiker offline Klik hier om het gebruikersprofiel van deze gebruiker te zien
De Administrator heeft publieke schrijf toegang geblokkeerd.
 
Ga naar bovenkantPagina: 12
Moderators: Rik, Roy