问题描述:

I have the following code for showing date/time stamp on my site:

<div id="clockbox" style="<font-size:9pt; padding:3px; text-align: center; text-transform: lowercase; overflow: hidden; height: 17px">

&nbsp;</div>

<script type="text/javascript">

tday =new Array("Nedelja","Ponedeljak","Utorak","Sreda","Četvrtak","Petak","Subota");

tmonth=new Array("Januar","Februar","Mart","April","Maj","Jun","Jul","Avgust","Septembar","Oktobar","Novembar","Decembar");

function GetClock(){

d = new Date();

nday = d.getDay();

nmonth = d.getMonth();

ndate = d.getDate();

nyear = d.getYear();

nhour = d.getHours();

nmin = d.getMinutes();

nsec = d.getSeconds();

if(nyear<1000) nyear=nyear+1900;

if(nhour == 0) {ap = " AM";nhour = 12;}

else if(nhour <= 11) {ap = " AM";}

else if(nhour == 12) {ap = " PM";}

else if(nhour >= 13) {ap = " PM";nhour -= 12;}

if(nmin <= 9) {nmin = "0" +nmin;}

if(nsec <= 9) {nsec = "0" +nsec;}

document.getElementById('clockbox').innerHTML=""+tday[nday]+", "+ndate+". "+tmonth[nmonth]+" "+nyear+". "+nhour+":"+nmin+":"+nsec+ap+"";

setTimeout("GetClock()", 1000);

}

window.onload=GetClock;

</script>

It is showing nicely on all pages unless I have following lines on the same page:

<div class="clickdesk-widget">

<script type='text/javascript'>

var _glc =_glc || [];

_glc.push('<?php echo $widgetid; ?>');

var glcpath = (('https:' == document.location.protocol) ? 'https://contactuswidget.appspot.com/livily/browser/' : 'http://gae.clickdesk.com/livily/browser/');

var glcp = (('https:' == document.location.protocol) ? 'https://' : 'http://');

var glcspt = document.createElement('script'); glcspt.type = 'text/javascript'; glcspt.async = true;glcspt.src = glcpath + 'livechat.js';

var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(glcspt, s);

</script>

</div>

What is the problem there, can anybody help?

网友答案:

You are declaring a global variables d, nday, etc. here:

d = new Date();
nday   = d.getDay();
nmonth = d.getMonth();
ndate  = d.getDate();
nyear = d.getYear();
nhour  = d.getHours();
nmin   = d.getMinutes();
nsec   = d.getSeconds();

try declare local variables instead (I guess that d variable is the root of your problenm because obfuscated code uses variable names like this) this way:

var d = new Date();
var nday   = d.getDay();
var nmonth = d.getMonth();
var ndate  = d.getDate();
var nyear = d.getYear();
var nhour  = d.getHours();
var nmin   = d.getMinutes();
var nsec   = d.getSeconds();

If it is online, send a link.

相关阅读:
Top