Skip to content

Instantly share code, notes, and snippets.

@matthewford
Created December 5, 2010 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewford/729591 to your computer and use it in GitHub Desktop.
Save matthewford/729591 to your computer and use it in GitHub Desktop.
detecting a click on ads in an iframe/flash banner
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var ad = $("#ad-1");
var pos = ad.offset();
var adWrapID = ad.next().attr('id');
var adWrap = $('#'+adWrapID);
adWrap.offset(pos);
adWrap.live('mouseenter', function(){
$(this).hide();
console.log("Log click to the ad via ajax");
setTimeout(function() {
$('#'+adWrapID).show();
console.log("Assume they haven't clicked on the add so cancel the click via ajax"); //This only works if not opening a new browser tab
// $("html").mousemove(function (e) {
// console.log(e.pageX + ' ' + e.pageY);
// }); //better way would be to bind to mouse move and see if they have moved after a time to cancel the click
}, 2500);
})
});
</script>
</head>
<body>
<p>Some site content</p>
<div id="ad-1" class="ad-click" style="width:300px;height:250px;">
<!-- 3rd party ad -->
<script type="text/javascript">
google_ad_client = "ca-pub-7959756410218649";
/* test */
google_ad_slot = "8131570945";
google_ad_width = 300;
google_ad_height = 250;
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</div>
<div id='123456' class="ad-wrap" style="width:300px;height:250px;z-index:9999;position:absolute;">
</div>
<p>Some more site content</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment