views:

41

answers:

2

Firstly both the parent page and the iframe are hosted on the same server (my localhost on WAMP) so same origin policy should not be an issue here.

I can't get the trigger to work. My iframe has the id of iframe.

$(window).load(function(){
  //iframe ad hovers
  $('#iframe').contents().find('body div').click(function(){
    alert('do something here');
  });
}); 

what am i doing wrong?

+1  A: 
Pointy
Hmm can't rely on jquery being in the iframe'd page unfortunately.
Haroldo
Well I'm wrong anyway - as jAndy said up in his comment, that seems to work just fine for me.
Pointy
$('#iframe').load() - perfect, thanks Pointy!
Haroldo
A: 

Your code is not wrong; i think the only mistake you are doing is that you are asking for the iframe's content on the parent page load which means at this stage the iframe has not been loaded yet.

Try my quick example http://jsfiddle.net/UFM44/4/ It is same as your code but i trigger it after clicking on "now" link. if you then click on the logo you can see the alert() message.

Mouhannad
Thanks Mouhannad, definitely looking in the right direction
Haroldo