how to intercept mouse clicks ... ads.

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
roRisc
Forum Newbie
Posts: 5
Joined: Fri Apr 09, 2004 11:02 pm

how to intercept mouse clicks ... ads.

Post by roRisc »

I'm looking for a way to make ads dissapear once visitors have clicked on them...

here's something similar:
http://www.nukephotogallery.com/modules.php?name=Forums
.. see the '+' and '-' for the blocks?
I was just looking through this site's code.. and thinking maybe someone already got this figured...

now.. how do I intercept the click on the add?

Code: Select all

<div align="center">
  <script type="text/javascript"><!--
    google_ad_client = "pub-31838509993581**";
    google_ad_width = 728;
    google_ad_height = 90;
    google_ad_format = "728x90_as";
    google_ad_channel ="39426832**";
    google_color_border = "7F91A6";
    google_color_bg = "F7F8FC";
    google_color_link = "32475F";
    google_color_url = "008000";
    google_color_text = "000000";
   //--></script>
   <script type="text/javascript"
     src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
   </script>


Thank you!

Please pitch in with remarks, thoughts, other ideas..
maybe innovate on what I've come up with


got some ideas while searching other forums..

..I could put a "show Ads" link, and when users clicks it, a cookie deletes itself thus turning ads on again.
does anyone have this already implemented?

Also...
I could add some JavaScript Code to open a new window that loads a page that will set a cookie that says that the user has clicked on the links, the page automatically close itself again. ~ or something like that

...I like the cookie aproach. but I have little clue on how to code this. is it possible?
Cheers!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

document.onclick
or
document.onmousedown
or
document.onmouseup

handle the event, then let it keep passing through the system.

in IE don't set window.event.cancelBubble to true and return false (I think)
in Mozilla variants, just return false (again, I think)
roRisc
Forum Newbie
Posts: 5
Joined: Fri Apr 09, 2004 11:02 pm

Post by roRisc »

what kind of event is this?

if document.onmouseX is on the whole document. how can I tell where the click was made?
pages are dynamic...

thank you.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's stored in the event object. Each is slightly different between the IE/Moz bits.

Moz passes the event object when calling the event handler. IE has it stored in window.event
roRisc
Forum Newbie
Posts: 5
Joined: Fri Apr 09, 2004 11:02 pm

Post by roRisc »

you mean something like this?

Code: Select all

<html>
<head>
<script language="javascript">
function ads(objIn) {
   var obj = document.getElementById(objIn);
   if (obj.style.display == "inline") {
      obj.style.display = "none";
   } else {
      obj.style.display = "inline";
   }
}
</script>
</head>
<body>
<a href="javascript:ads('ad1');">Ads?</a>
<BR>
<div id="ad1" style="display:inline">
Buy my stuff! Now!! PLEASE!!!! BUY BUY BUY!!!!!!!!!!
</div>
</body>
</html>
this just hids text clicking the link.
I do not see the code of the ad itself since it is in an iframe...

please elaborate on your idea.. so I can further undergo searches...
Thank you.

other ideas are welcomed too
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

okay. The event object contains both screen and page relative positions for where the click occurs. Since you know the ad's dimensions, simply look for a click inside that rectangular region. If a click happens there, tell the ad to hide.

Not telling the browser to cancel the event propagation, allows the click to pass through to other objects and their event handlers. Although this may not work for iframes, as they are considered top level, always. You may or may not receive the event, since it is an iframe. This can be figured out through simple testing.

Similarly, you can have your parent page set an event handler in the iframe. You'll have to make sure that you call any event handler that was being used in that iframe.
roRisc
Forum Newbie
Posts: 5
Joined: Fri Apr 09, 2004 11:02 pm

Post by roRisc »

thank you.

do you happen to have any links on how-to's for this topic?
Cheers!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I don't sorry.
Post Reply