0

In my app, I need to open an iFrame, whose content comes from the same domain and uses the same protocol, and port number.

For the content in the iFrame, I want to have mouse click events, and I need to catch these events by using JQuery's $('#my-item").click(function(){ ..... }). The javscript code is in a file loaded TOGETHER with the iFrame content.

However, the mouse click event is not caught by my javascript code. I am kind of confused. I really want to KNOW and LEARN about how to do Javascript within content in an iFrame. I am not talking about javascript code loaded with the iFrame's parent.

Thanks for any input and pointers.

Regards.

curious1
  • 12,884
  • 33
  • 109
  • 194
  • 1
    Ignore the iFrame for a moment - does your code work if you load the iFrame page in a browser window? –  Apr 04 '14 at 00:42
  • @Mike, thanks for pointing me to the right direction!!! I load all my Javascript code on a page by page basis. The javascript code for the iFrame page was actually NOT loaded. So things seem working. Am I right that the javascript loaded with iFrame should work just like usual if the javascript works only on the content in the iFrame. Correct? – curious1 Apr 04 '14 at 01:17
  • @Mike, you can answer my comment above and post it? I will select it as the answer. I always had a "mystery" feel about Javascript in iFrame. Your helped me and I feel excited to move on with my iFrame solution. – curious1 Apr 04 '14 at 02:18
  • AFAIK if you're working solely within an iFrame everything should work just as if you were working in a browser window. Someone else may know of some exceptions. Accessing elements across the iFrame boundary is a potential security issue so there are cross-domain restrictions there, but if your iFrame content originates from the same place as the main page this shouldn't be a problem. –  Apr 04 '14 at 03:03
  • @MikeW, if you can make your post a reply. I will select it as the answer. I dont want this question looks like unanswered. Your reply will certainly help others. Thanks. – curious1 Apr 04 '14 at 16:10

0 Answers0