Don't work jQuery click() method.?

I get a script and it have image and link, i want after click on image alert ok and after alert go to a link (href). That’s a cross domain iframe.How is it?


<div class="addv">
    <script type="text/javascript">var anetwork_pram = anetwork_pram || [];anetwork_pram["aduser"] = "1423687058";anetwork_pram["adheight"] = "250";anetwork_pram["adwidth"] = "300";</script><script type="text/javascript" src=""></script>


Js Code:

$(".addv").on("click", "a", function(event) {
    alert('ok'); //should alert ok


What do i do?

Having the ad there doesn’t do the alert. Without it, it clicks though.

I want click on iframe and get alert.?

You also took out the “a”.

Maybe if you changed the “a” to “iframe”?
Of course there would need to be one inside the addv div for either to work.

True. Although I ddi test and changed it to div/iframe/etc, and it didn’t work.

I was googling and apparently it won’t work without revamping it. He meant ot target the anchor inside of the iframe. Perhaps he needs to put this jquery inside of the iframe page.

There is no click event for an iframe and you would probably need something like this to do it properly.

You could however absolutely place a link over the top of the iframe and set the destination of the link to the same as that you wanted for the iframe. You could then add an alert to the link.


<meta charset="utf-8">
<title>Untitled Document</title>
.addv {
.mylink {

<div class="addv"> <a href="" class="mylink"></a> 
		<script type="text/javascript">var anetwork_pram = anetwork_pram || [];anetwork_pram["aduser"] = "1423687058";anetwork_pram["adheight"] = "250";anetwork_pram["adwidth"] = "300";</script><script type="text/javascript" src=""></script> 
<script src=""></script> 

    $("body").on("click", ".mylink", function(event) {
        alert('ok'); //should alert ok

Of course that means the iframe is basically no more than image and will have no interaction.

ok.Very true, How is after alert ok it go to image url (a:link html tag in iframe)?

I’m not quite sure of the question but if you are referring to my demo then the alert is triggered on the anchor.

<a href="" class="mylink"></a> 

After you close the alert the anchor just goes on about its usual business and follows the clicked link via its href attribute - as usual.

You can’t have any link in the iframe (or the iframe itself) be part of an onclick routine (as mentioned in that link I already gave above).

I assumed you just wanted to click the iframe and go to a pre-destined destination which the code I supplied will do. :smile:

I tried as, see it: for geting image link and redirection to it. but don’t work for me. ?

    $(".addv iframe").load(function(){
         var iBody = $(".addv iframe").contents().find("body");
         var iDiv = iBody.find("a");
         /*code to change the div content*/

Normally, when you click on the image opens a new page.Now I want to give a alert before opening a new tab.(I want to open in a new page will show the alert .) How can it be done?

You can’t find anything in an iframe. Its not yours to find. It’s another site.

Think of an iframe as another site. You can’t put code on your page and have it affect someone else’s site.

The only way to can have control over an iframe is if you have access to the iframe’s code and then you can add code inside the iframe that will allow you to communicate with the parent page. (Or if the iframe is on the same domain then some browsers allow limited access.)

You can only do what I have shown and send the user to a link that you know. You can’t send them to a random link in an iframe.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.