javascript读取鼠标位置并写入文件

javascript to read mouse position and write to a file

本文关键字:文件 位置 读取 鼠标 javascript      更新时间:2023-09-26

当用户点击HTML页面上的图像时,我试图获取鼠标指针的坐标,用户必须点击图像,我想使用javascript获取点击位置的坐标,并写入服务器本身的文件。我正在使用站点44从我的dropbox帐户托管。我无法将坐标写入文件。

<html>
<head>
<title>image click test</title>
<script type="text/javascript">
function coord()
{
var x;
var y;
x=event.offsetX; 
y=event.offsetY;
ActiveXObject("Scripting.FileSystemObject");
var file = object.CreateTextFile("hello.txt",false);
file.WriteLine(x);
file.WriteLine("by");
file.WriteLine(y); 
file.Close();
}
</script>
</head>
<body onclick="coord()">This is a sample image, please click anywhere on the image. But ensure you click only once.<br>
<img src="index_catfish.jpg" alt="Click Image" usemap="#imageclick"/>
<map name="imageclick">
</map>
</body>
</html>

Browser的JS实现无法直接写入本地文件。唯一的方法是将数据存储在cookie或localStorage中(如果浏览器支持的话)。