iFrame onClick

Discussion in 'JavaScript' started by Pudge1, Oct 13, 2013.

  1. #1
    Does anyone have a good method for adding an onClick event to an iFrame? I've tried searching around for some solutions online and none of the solutions I found have worked for me. And setting the onClick of the body doesn't execute the function nor does just setting it for the iFrame itself
     
    Pudge1, Oct 13, 2013 IP
  2. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #2
    HuggyStudios, Oct 14, 2013 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #3
    since the contents of an iframe are actually a browser window sitting OVER the host content, you shouldn't be able to trap onclick over it at all in ANY browser. "Just not allowed " for a whole host of security reasons.

    Though again, this is 2013, not 1998 -- why are you even trying to use iframes in the first place?
     
    deathshadow, Oct 14, 2013 IP
  4. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #4
    If you have access to the iframe codebase, then there are several ways you can implement communications between the child and parent. A really nice way to do so is by creating a proxy on each site that relays the information back and forth.

    There were other solutions like using flash overlay, which isn't 100% perfect but works on double clicks.

    The issue here is mainly same origin policy, where your script needs to be on the same TLD as the site it includes if you want to access/modify it.
     
    ThePHPMaster, Oct 15, 2013 IP