我使用以下代码写入.csv
文件
<html>
<head>
<script language="javascript">
function WriteToFile(passForm) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fileLoc = "C:\\Users\\Owner\\Desktop\\test\\sample.csv";
var file = fso.CreateTextFile(fileLoc, true );
file.writeline(passForm.FirstName.value + ',' + passForm.LastName.value);
file.Close();
alert('File created successfully at location: ' + fileLoc);
}
</script>
</head>
<body>
<p>create a csv file with following details -</p>
<form>
Type your first name: <input type="text" name="FirstName" size="20">
Type your last name: <input type="text" name="LastName" size="20">
<input type="button" value="submit" onclick="WriteToFile(this.form)">
</form>
</body>
</html>
</br></br></html>
它适用于IE。然而,对于其他浏览器,它会抛出
Uncaught ReferenceError: ActiveXObject is not defined
我在网上查了可能的解决方案
我尝试将该代码包含在上面的代码中,但是它没有用。