【发布时间】:2017-06-24 17:47:17
【问题描述】:
我们如何跟踪 iframe 上的点击(如任何 advt。)并根据网站用户分别使用 advt id 和用户 id 在我自己的数据库(使用 ajax)中记录该事件
-
我在父 div 上尝试过 onclick(如下所示)事件,但没有工作 -
$('div.ad').on('click', function(){ $.ajax({ url: 'clickevent.php', type: 'POST', data: { 'id': adId }, dataType: 'json', success: function(data){ // show success msg to user }, error: function(){ // show failure msg } }); }); -
我尝试在光标位于 iframe 上方时进行聚焦和模糊
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> <script> jQuery(function( $ ){ var isOverAd = false; $( "iframe[ id *= google ]" ) .mouseover(function(){ isOverAd = true; }) .mouseout(function(){ isOverAd = false; }); $( window ).blur( function(){ if (isOverAd){ $.ajax({ url: 'clickevent.php', type: 'POST', data: { 'id': adId }, dataType: 'json', success: function(data){ //show success msg }, error: function(){ //show failure msg } }); } }).focus(); }); - 我也尝试过当鼠标在 iframe 上时窗口丢失模糊
- 我已映射像素($0 值)它也无法正常工作。
但没有任何效果......如果你能帮助我,我将非常感激
【问题讨论】:
-
这个错误表明你没有在页面中添加jquery文件。
-
@FarzinKanzi 不,实际上我在我的项目中做过,但在这里我只发布了我的代码
-
所以你创建的代码sn-p是没用的。
标签: javascript php jquery html iframe