使用HTML / java追加?

时间:2010-10-27 09:20:01

标签: javascript html append

我想用HTML或java附加一个.txt文件我知道这是可能的 但继续遇到ActiveX警告,在这种情况下只是令人讨厌(我们知道ActiveX停止如此愚蠢的教条)

在没有AxtiveX提示的情况下,只有一种简单的脚本编写方法吗?

当前脚本如下(或至少snippit)

<title>fruit.txt </title>
<SCRIPT LANGUAGE='JavaScript'> 
function WriteToFile() { 
try { 
var fso, s; 
fso = new ActiveXObject("Scripting.FileSystemObject"); 
s = fso.OpenTextFile("C:\\TESTAPEND\\TESTAPEND.txt" , 8, 1, -2); 
s.writeline(document.ietmdata.name.value); 
s.Close(); 
} 
catch(err){ 
var strErr = 'Error:'; 
strErr += '\nNumber:' + err.number; 
strErr += '\nDescription:' + err.description; 
document.write(strErr); 
} 
} 


function WriteToFile2() { 
try { 
var fso2, s2; 
fso2 = new ActiveXObject("Scripting.FileSystemObject"); 
s2 = fso2.OpenTextFile("C:\\TESTAPEND\\TESTAPEND.txt" , 8, 1, -2); 
s2.writeline(document.ietmdata2.name2.value); 
s2.Close(); 
} 
catch(err2){ 
var strErr2 = 'Error:'; 
strErr2 += '\nNumber:' + err2.number; 
strErr2 += '\nDescription:' + err.description; 
document.write(strErr2); 
} 
} 

function WriteToFile3() { 
try { 
var fso3, s3; 
fso3 = new ActiveXObject("Scripting.FileSystemObject"); 
s3 = fso3.OpenTextFile("C:\\TESTAPEND\\TESTAPEND.txt" , 8, 1, -2); 
s3.writeline(document.ietmdata2.name2.value); 
s3.Close(); 
} 
catch(err2){ 
var strErr3 = 'Error:'; 
strErr3 += '\nNumber:' + err3.number; 
strErr3 += '\nDescription:' + err.description; 
document.write(strErr3); 
} 
} 

</SCRIPT> 
</head>
<body>

<p class=rvps3><span class=rvts13>Append acaddoc.lsp</span></p>
<p class=rvps2><img border=0 width=80 height=129 alt="" hspace=1 vspace=1 src="VTS_LOGO.jpg"></p>
<hr noshade size=1 style="color : #000000">
<p><span class=rvts10>Drawing Analyser 1.1</span></p>
<hr noshade size=1 style="color : #000000">
<p><br></p>
<p>

<center>If your Acaddoc.lsp file resides where AutoCAD installed them by default, simply click append next to the version of AutoCAD you want to apply the Drawing Analyser 1.1 program to. <br> <br> <br> <br> <table border="1"><tr><th> 

<form action="test.hta" method="post" name="ietmdata"> 
&nbsp; AutoCAD 2006 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <INPUT TYPE=BUTTON VALUE="APPEND" onClick="WriteToFile(this.form); window.location.href='Append_acaddoc_LSP_MODULE_2.html'"></table border="1"></tr></th><div id="myarea" style="visibility:hidden"> <textarea name="name" cols="40" rows="1"> 

Appels

</textarea> </div> 

</form> 

<table border="1"><tr><th> 

<form action="test.hta" method="post" name="ietmdata2"> 
&nbsp; AutoCAD 2009 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <INPUT TYPE=BUTTON VALUE="APPEND" onClick="WriteToFile2(this.form); window.location.href='Append_acaddoc_LSP_MODULE_2.html'"></table border="1"></tr></th><div id="myarea2" style="visibility:hidden"> <textarea name="name2" cols="40" rows="1"> 

Pears

</textarea> </div> 

</form> 

<table border="1"><tr><th> 

<form action="test.hta" method="post" name="ietmdata3"> 
&nbsp; AutoCAD 2010 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <INPUT TYPE=BUTTON VALUE="APPEND" onClick="WriteToFile3(this.form); window.location.href='Append_acaddoc_LSP_MODULE_2.html'"></table border="1"></tr></th><div id="myarea3" style="visibility:hidden"> <textarea name="name3" cols="40" rows="1"> 

Bannanas

</textarea> </div> 

</center></form> 

2 个答案:

答案 0 :(得分:0)

如果您在本地计算机上看到IE中的activex提示,请不要担心在服务器上运行代码时不会收到该警告

答案 1 :(得分:0)

你有几个选择,但如果ActiveX适合你,那么我建议你坚持使用它,因为提示是有原因的,这是一个安全风险,任何想要合法访问你的本地文件的web应用程序,它通常会发出警告信息,因为如果没有,就像明天太阳升起一样,它会被利用。

您也可以使用Applet(Java),但这是过度的,但如果使用适当的证书,它将绕过许多安全警告和问题。它是您网站中的一个重要组件,但其优点是所有支持Applet的浏览器都能够运行您的代码,这与使用ActiveX时不同,只有您支持浏览器的浏览器。

或者您可以等待HMTL 5开发,它本身应该支持文件IO。