tags:

views:

57

answers:

3

I have a javascipt code something like

<script type="text/javascript" src="http://ads..........." ></script>

this script shows a banner. i want to use onClick event with this script without disturbing the banner click. is that possible?

+1  A: 

Yes if the banner is not wrapped in an iframe that is cross domain, but the question is... onClick event on what? the banner? the page? another element?

use addEventListener/addEvent or a JS library to add the event. If this kills the banner be sure to take the banner's onclick property and add it as well to the banner.

bmeck
Yes, a good idea to deploy listeners with a library, e.g. jQuery.
Ain
I have no idea of how to deploy a listener. Can you please guide me or show me some example? I want to open the banner page when someone clicks on a banner and also want to open a separate window on onclick that can be any url like www.google.com
Rizwan Aaqil
+1  A: 

Those scripts usually produce dynamic content via document.write. If you examine the resulting DOM (e.g., via Firebug in FireFox, or Dev Tools in Chrome, etc.), you can get an idea of what the resulting structure is. If there's a top-level image or link, you can hook it with a DOM2 handler (addEventListener is the standard form; IE uses attachEvent instead; Javascript libraries like Prototype or jQuery can help iron out the inconsistencies for you). That would let you see a click without disturbing its underlying action (provided you don't cancel the event, but you have to do that on purpose, so you should be okay.)

T.J. Crowder
Yes, good suggestion. Firebug in Firefox or Web Inspector in Safari/Chrome.
Ain
A: 

Process that click through the handler, e.g.

<a href="#" onclick="javascript:yourFunctionThatEventuallyDoesTheRedirect('URLToRedirect')"><!-- Banner image --></a>

Ain
Rizwan Aaqil
Rizwan Aaqil