开发者

How to save log to .txt [closed]

开发者 https://www.devze.com 2023-03-21 13:36 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

How to save log to .txt ?

<html>
<head>
<title>Javascript Stopwatch</title>
<script language="javascript">

var base = 60;

var clocktimer,dateObj,dh,dm,ds,ms;
var readout='';
var h=1;
var m=1;
var tm=1;
var s=0;
var ts=0;
var ms=0;
var show=true;
var init=0;
var filePath = "/Users/ResetOfDirectoryPath/testWrite.txt";

function getCheckedValue(radioObj) {
if(!radioObj)
    return "";
var radioLength = radioObj.length;
if(radioLength == undefined)
    if(radioObj.checked)
        return radioObj.value;
    else
        return "";
for(var i = 0; i < radioLength; i++) {
    if(radioObj[i].checked) {
        return radioObj[i].value;
    }
}
return "";
}

function uncheckedRadio() {

var radio_1 = document.clockform.gName;
var radio_2 = document.clockform.aName;       

if(radio_1.length == undefined)
    radio_1.checked = false;
else
    for(var i = 0; i < radio_1.length; i++)
        radio_1[i].checked = false;

if(radio_2.length == undefined)
    radio_2.checked = false;
else
    for(var i = 0; i < radio_2.length; i++)
        radio_2[i].checked = false;
}

unction clearALL() {
    clearTimeout(clocktimer);
    h=1;m=1;tm=1;s=0;ts=0;ms=0;
    init=0;show=true;
    readout='00:00:00.00';
    document.clockform.clock.value=readout;
    document.clockform.m0.value = '';
    uncheckedRadio();
    nrGola = 1;
}

var nrGola = 1; 
function addMEM() {
if (init>0)
{
    var mC = document.clockform.m0;
    var gol = getCheckedValue(document.clockform.gName);
    var asy = getCheckedValue(document.clockform.aName);

    if(gol != '')
    {
        var mesOut = nrGola + " G: " + gol;

        if(asy != '')
        {
            if(asy == gol)
            {
                alert('Error, asysta taki sam jak strzelca');
                uncheckedRadio();
                return false;
            }

            mesOut = mesOut + ", A: " + asy;
        }
        else
            mesOut = mesOut + ", A: brak";

        mesOut = mesOut + ", " + readout;

        if(mC.value != '')
            mC.value = mC.value + "\n" + mesOut;
        else
            mC.value = mesOut;
       nrGola++;     
       uncheckedRadio();              
    }
    else
        alert('Nie wybrano strzelcy');
}
}


function startTIME() {

var cdateObj = new Date();
var t = (cdateObj.getTime() - dateObj.getTime())-(s*1000);

if (t>999) { s++; }

if (s>=(m*base)) {
    ts=0;
    m++;
    } else {
    ts=parseInt((ms/100)+s);
    if(ts>=base) { ts=ts-((m-1)*base); }
    }

if (m>(h*base)) {
    tm=1;
    h++;
    } else {
    tm=parseInt((ms/100)+m);
    if(tm>=base) { tm=tm-((h-1)*base); }
    }

ms = Math.round(t/10);
if (ms>99) {ms=0;}
if (ms==0) {ms='00';}
if (ms>0&&ms<=9) { ms = '0'+ms; }

if (ts>0) { ds = ts; if (ts<10) { ds = '0'+ts; }} else { ds = '00'; }
dm=tm-1;
if (dm>0) { if (dm<10) { dm = '0'+dm; }} else { dm = '00'; }
dh=h-1;
if (dh>0) { if (dh<10) { dh = '0'+dh; }} else { dh = '00'; }

readout = dh + ':' + dm + ':' + ds + '.' + ms;
if (show==true) { document.clockform.clock.value = readout; }

clocktimer = setTimeout("startTIME()",1);
}

function findTIME() {
if (init==0) {
    dateObj = new Date();
    startTIME();
    init=1;
    } 

}

/*
var times = {};
window.onload=function() {
var inpt = document.getElementsByTagName("input");
for (var i=0,n=inpt.length;i<n;i++) {
if (inpt[i].type=="radio") inpt[i].onclick=function() {
    times[this.id]=this.form.m0.value=this.form.clock.value;

} 
}
}
*/

function showTimes() {

var temp = document.clockform.m0.value;

if(temp != '')
{   
    uriContent = "data:text/plain;charset=utf-8," + encodeURIComponent(temp);
    newWindow=window.open(uriContent, 'txt');
}
}



</script>
</head>
<body bgcolor=tan>
<form name="clockform">
<table bgcolor=cornsilk align=center cellpadding=5 border=1 bordercolor=burlywood><tr><td>
<table cellpadding=3 cellspacing=0 border=0 align=center>
<tr&开发者_Go百科gt;
<td bgcolor=wheat><input name=clock value="00:00:00.00" style="text-align:center; width:174px; height:35px; font-size:24; font-weight:bold"></td>
<td valign=top bgcolor=wheat><input name=clearer type=button value="Reset" onclick="clearALL()"></td>
</tr>
<tr>
<td colspan=2 bgcolor=wheat>
<input name=starter type=button value="Start" style="width:97px; font-weight:bold" onclick="findTIME()">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<input name=marker type=button id ="dupa" value="Mark" style="width:84px" onclick="addMEM()"><br><font style="font-size:9pt">&nbsp;</font></td>
</tr>

<tr><td>
<input type="radio" name="gName" value="1" /> 1<br>
<input type="radio" name="gName" value="2" /> 2<br>
<input type="radio" name="gName" value="3" /> 3<br>
<input type="radio" name="gName" value="4" /> 4<br>
<input type="radio" name="gName" value="5" /> 5<br>
<input type="radio" name="gName" value="6" /> 6<br>
</td>
<td>
<input type="radio" name="aName" value="1" /> 1<br>
<input type="radio" name="aName" value="2" /> 2<br>
<input type="radio" name="aName" value="3" /> 3<br>
<input type="radio" name="aName" value="4" /> 4<br>
<input type="radio" name="aName" value="5" /> 5<br>
<input type="radio" name="aName" value="6" /> 6<br>
</td>
</tr>
<tr><td colspan="2">
<textarea name="m0"  style="text-align:left; width:83px cols="40" rows="5" readonly="readonly">
</textarea>
<input type="button" onclick="showTimes()" value="show times">
</td>
</tr>
</table>
</form>


</body>
</html> 


JavaScript, running in a browser, under normal security conditions, cannot access the user's file system.


You need to have ajax or something else that can write to the server with the right permissions to write to a log file on the server. The JavaScript itself can not write a log file to the server or the client as it is executed off the server and it does not have access to the clients computer (Image getting viruses through JavaScript if this was true)....Unless you give explicit write access which is very unsafe and very complicated to do.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号