Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Add onclick event from iframe

    I am trying to add an onclick event to a dynamically generated element. This happens in an iframe, but the element is being added to the parent document, and I need to associate the onclick event with a function in the parent document. When I add it from the iframe and then click on the image, I get an error saying the function does not exist.

    Code:
    var img = parent.document.createElement('img');
    img.onclick = function() { doSomething() };
    parentDiv.appendChild(img); //parentDiv is an element in the parent document
    I also tried: img.setAttribute('onclick', 'doSomething(this);');
    This worked great in Firefox, but not in IE.

  • #2
    New to the CF scene
    Join Date
    Nov 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I couldn't figure out how to get this to work, so I ended up just moving the function to the parent document and calling it from the iframe: parent.addImageElement();


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •