[x]

deviantART

 

Seeking Help with IFrame Events

Fri Jun 6, 2008, 6:07 PM
EDIT: The problem with making the Firefox add-on has been resolved. The solution: I won't do it. I'll wait for someone else to do it. I know there are at least five other people on the Internet who long for Firefox to ALWAYS show a broken image placeholder, even if the image has ALT text. So someone's bound to make the add-on I want eventually.

But now I have a new problem.

I'm trying to make some easier editing tools for my site -- so that I can stop being a lazy -sshhole update much faster and much easier. How the tool works is, the page is divided in half. The top half is an IFRAME that shows a sample videos page. You click on an element in there (video title, video description, etc.) and forms appear in the bottom half to edit it.

Now here's the problem.

This is the line of code that adds an event handler to the IFRAME. This event handler detects clicks -- anywhere: it allows me to register ONE event handler to not only detect all clicks in the IFRAME but also detect WHAT was clicked -- in the IFRAME.
document.getElementById("interactivePreview"). contentDocument.addEventListener("click",detectClicks,true);
(the space before "contentDocument" was added to facilitate non-glitchy text-wrapping and is not present in the code, so that's not the problem).

Now the issue is, if I wrap that line in an alert() and call it from the address bar, it works PERFECTLY. But it doesn't do ANYTHING at all when it's run from the script itself. It's not in a function, it's in the page containing the IFRAME and it is in the global scope.

detectClicks is my wonderful function to detect the clicks in the IFRAME. Its code is not important or relevant to the issue. The problem is, I just can't seem to find a way to get that event listener to work from the script, only from the address bar. As I intend for these editors to be used by the other staff member on my site (and any future ones that I let join the staff) it needs to be user-friendly. That means I gotta find a way to get this to work from the page.

Any help?




I am sorted in :icondeviantartcommunity: under Varied Artists.








Non-subscriber "Stamps":
:iconbringbcbwbackplz::iconbringbcbwback2plz:

  • Mood: Confused
  • Listening to: Crossfade - Colors

Devious Comments

love 0 0 joy 0 0 wow 0 0 mad 0 0 sad 0 0 fear 0 0 neutral 0 0

Load up a debugger. It sounds like the code is firing before the referenced node is created, and as such doesn't actually exist, which would explain why calling from the address bar would do it: by that time, its already there.

Try window.addEventListener('DomContentLoaded',function(){Your eventlistener},false)


Just a thought. :shrug:

--
It's a simple question, Doctor: If the moon was made of ribs, would you eat it?! It's not rocket science; answer yes so we can move on.
BOOYAH!

The event listener didn't work, but that suggestion got me to try using the IFRAME's onLoad attribute, which did!

Thanks :D :D

--
"I can levitate birds. No one cares."
~ Steven Wright (When The Leaves Blow Away)


Creative Worlds Forums
:) Glad I could help.

--
It's a simple question, Doctor: If the moon was made of ribs, would you eat it?! It's not rocket science; answer yes so we can move on.

Journal History

Site Map