同一页面上有很多链接。这些链接将开始不同的下载。 我想要做的是,当单击链接开始下载时,我还想将 iframe 位置更改为 php 页面以增加下载点击计数器。
代码需要位于每个链接的 onClick
事件中,因为同一页面上有很多链接。
我想要这样的东西:
<a href="download001.zip" onClick="iframe.location.href='hits_counter.php?file=download001>Start download 001</a><br>
<a href="download002.zip" onClick="iframe.location.href='hits_counter.php?file=download002>Start download 003</a><br>
<a href="download003.zip" onClick="iframe.location.href='hits_counter.php?file=download003>Start download 003</a><br>
...
必须激活两个事件:下载文件并更改 iframe href
最佳答案
如果有很多,onClick 不是解决方案
使用jquery,你可以用类似的东西来处理所有这些:
$("a").click(function(){
$.get("hits_counter.php",{ file:$(this).attr("href") });
});
不再需要 iframe
关于单击链接时javascript更改iframe位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17356301/