JavaScript 点击跟踪器、ahref 链接

发布于 2025-01-08 03:29:58 字数 686 浏览 1 评论 0原文

我有一个为 swf 文件生成动态链接的脚本...

例如,当他们单击链接时,该脚本将生成

<a href=" { url } / swf / file . swf ">Click File</a>

,它会在灯箱中打开 swf 文件,因此我无法使用 php,因为它的客户端

我可以更改脚本,以便它将添加

onClick="javascript: FUNCTION;"

我如何编写一个 javascript 函数来写入名为

“click-log.txt”的基本目录中的文件,其中包含链接的 href 和时间戳...

假设单击的链接具有

http://example.com/data/swf/file1.swf

我希望将日志文件写入的

1329849120 , 82.**.***.*** , /data/swf/file1.swf

url假设编写完整文件更容易路径,但我会很高兴只使用文件名,甚至完整的网址,如果它是最简单的......

我已经对此进行了编码,以便在页面加载时与 php 一起使用多次,但无法编写 javascript 来执行此操作.. ...

谢谢大家

i have a script that produces dynamic links for swf files....

eg the script will produce

<a href=" { url } / swf / file . swf ">Click File</a>

when they click the link it opens the swf file in a lightbox so i cannot use php, as its client side

i can change script so that it will add

onClick="javascript: FUNCTION;"

how would i word a javascript function to write to a file in base directory named

'click-log.txt' with href of link and timestamp...

lets say the link clicked has the url

http://example.com/data/swf/file1.swf

i would like the logfile written as

1329849120 , 82.**.***.*** , /data/swf/file1.swf

i presume its easier to write the full file path, but i would be happy with just the filename, or even the full url, if it is easiest....

i have coded this to work with php on page load many times, but cannot write javascript to do this action.....

thanks guys

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花辞树 2025-01-15 03:29:58

Javascript 是一种客户端语言,它在客户端(访问者)计算机上执行,对于这种日志记录,您应该使用 PHP 等服务器端语言在您的网络服务器上创建日志文件。您可以尝试查看此网站的简单日志功能。

http://svidhya.wordpress.com/2008/ 02/01/创建并写入日志文件/

Javascript is a client side language, it is executed on the client's (visitors) computer, for this kind of logging you should use a server side language like PHP to create a log file on your webserver. You can try looking at this web-site for a simple log function.

http://svidhya.wordpress.com/2008/02/01/creating-and-writing-log-files/

若无相欠,怎会相见 2025-01-15 03:29:58

这进入 head (ajax 请求),

<script type="text/javascript">
function clickLog(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","click-log.php?url="+str,true);
xmlhttp.send();
}
</script>

这将打开带有 url 参数 'str' 的 'click-log.php' <<< 'str' 在 onclick 函数括号中定义为 'this.href'

<a href=" { url } / file .swf " onClick="clickLog(this.href)">Click Me</a>

,当单击链接时,它会打开并处理 php 文件,其中链接 href (this.href) 作为参数 url=

脚本甚至附带了 this。 ....

<div id="txtHint"></div>

如果你将此 div 放在要单击的链接下方,它将回显 click-log.php 输出的任何内容......

这将在下面解释......

的 php 文件

<?php

$url = $_GET['url'];

$time = date('U');

$ip = $_SERVER['REMOTE_ADDR'];

$fp = fopen('click-log.txt', 'a');
$fwrite = fwrite($fp, $time.' , '.$ip.' , '.$url.'
');

// --- echo 'Log Written'; --- // 

?>

这是我写入 带有时间戳的文本文件“click-log.txt”的末尾, ip 和链接的 href 单击了

注释掉的 echo 行,一旦单击链接并且处理了 ajax 请求,就会将文本“Log Written”插入到“txtHint”div 中,

但所有使用的文件都位于基本目录中谁想在他们的网站上实现这个脚本可能已经知道如何更改文件位置等

....

.....感谢提供信息的人....另一个成功的脚本:)

ps,现在编写脚本以漂亮的图表和饼图形式向我显示日志文件:lmao:

this goes in head (ajax request)

<script type="text/javascript">
function clickLog(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","click-log.php?url="+str,true);
xmlhttp.send();
}
</script>

this opens 'click-log.php' with url parameter 'str' <<< 'str' is defined as 'this.href' in the onclick function brackets

<a href=" { url } / file .swf " onClick="clickLog(this.href)">Click Me</a>

when the link is clicked it opens and processes the php file, with the link href (this.href) as the parameter url=

the script even came with this.....

<div id="txtHint"></div>

if you place this div below the link to be clicked, it will echo whatever the click-log.php outputs......

this will be explained below....

this is my php file

<?php

$url = $_GET['url'];

$time = date('U');

$ip = $_SERVER['REMOTE_ADDR'];

$fp = fopen('click-log.txt', 'a');
$fwrite = fwrite($fp, $time.' , '.$ip.' , '.$url.'
');

// --- echo 'Log Written'; --- // 

?>

this writes to end of text file 'click-log.txt' with the timestamp, ip, and href of link clicked

the echo line that is commented out, will insert the text "Log Written" into the "txtHint" div once the link has been clicked and the ajax request processed

all files used are in the base directory however anyone who would like to implement this script on their site would probably already know how to change file locations etc

....

..... thanks for the info guys.... another successful script :)

ps, now to write the script to show me the logfile in pretty graphs and pie charts :lmao:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文