JillElaine / jquery-idleTimeout

Idle activity timeout and logout redirect for jQuery for multiple windows & tabs
Other
72 stars 79 forks source link

Doesn't attach to iframes created dynamically #14

Closed Connor9220 closed 9 years ago

Connor9220 commented 9 years ago

A iframe that is created dynamically (such as ones used by ckeditor when created in jquery-ui dialog) doesn't update the timeout with mouse or keyboard input.

I use jquery-ui with dialogs. and with-in those dialogs, I sometimes have CKeditor running. IF someone is in a dialog with a editor.. the timer times out, even if they're working because the iframe doesn't exist until AFTER the timeout script loads. Need a away to include that iframe when it loads. Is there a way to attach the events to it after it loads the editor?

JillElaine commented 9 years ago

My approach: detect when a dialog is opened, then run the "includeIframes" function to check for and include any new iframes.

This idea works...and activity within the dialog's iframe is detected...on my test site, but with one exception. If the parent page has one or more iframes on it that are from another domain (cross-site), then jquery.js throws an error: "Error: Permission denied to access property 'document'".

You can see the error in Firefox > Firebug > Console enabled on my iframe demonstration page, where I have an iframe from w3schools.com as an example of how you cannot detect activity within an iframe that is not within the same domain. http://jillelaine.github.io/jquery-idleTimeout/iframe-demo.html

If this "Permission denied" error is thrown, it somehow interferes with the inclusion of the new 'same domain' iframe that is within the new dialog box. If the error is NOT thrown, then the dialog's iframe is included in the activity detection!

Unfortunately, many pages have iframes from another domain, typically advertisements (which are sometimes filled with malware).

What do you think?

JillElaine commented 9 years ago

Ha! All I had to do was to put my iframe 'attachEvent' code within a try/catch block to catch the "Permission denied" error. It's an improvement to the code, too. I'll get this coded up soon. :-)

JillElaine commented 9 years ago

Added the ability to attach events to dynamic iframes. Iframes within newly opened dialog boxes are automatically added to 'activity detection'. Iframes dynamically inserted into the BODY of the document require a short snippet of script added to the same function that inserts the iframe: $.fn.idleTimeout().iframeRecheck();

Please read the README and the information on the demo page. http://jillelaine.github.io/jquery-idleTimeout/iframe-demo.html

I will keep this issue open until you report back. Thank you.

JillElaine commented 9 years ago

Modified the iframe inclusion code to allow only one 'activity event' listener to be attached to each 'same domain' iframe. As each iframe is inspected, if it is in the same domain, a css class is added to the iframe when the 'activity event' listener is attached. As new same domain iframes are added to the document, the iframe inspection function tests for this css class before the attachment of the listener.

JillElaine commented 9 years ago

Added the ability to find and include nested iframes in the event 'bubbling'.