JillElaine / jquery-idleTimeout

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

Modify jquery-idleTimeout script to use cookies instead of localStorage and to work across subdomains #20

Closed AdvantmedKinjal closed 8 years ago

AdvantmedKinjal commented 8 years ago

Hi All, I use JQuery-idleTimeOut.min.js for stay In and logout functionality.I have Multiple sub domains for parent domain. i.e main domain like a1.advantmed.com and sub domain like a2.advantmed.com,a3.advantmed.com,etc.I see the iframe demo for cross domain of JillElaine but our organization prohibited the use of iframe. so just little bit change I have done in this jquery. I am use this jquery plugIn and use cookie for get and set value instead of local storage. But Now one problem arise. "Stay In" button Is work properly for multiple tabs.Even When idleTimeLimit time complete and simply logout from all tabs working fine.But when click on "Logout" button of dialog box only one tab in which click button is redirect to log out url but in Other tabs not redirect or no any action performed. I have attached here updated code in this jquery plugIn. Please help to find out the actual problem.

Timeout.txt

Thanks in Advance

JillElaine commented 8 years ago

When you edit the jquery-idleTimeout code, please edit jquery-idleTimeout.js and not the minified code, jquery-idleTimeout.min.js. I use http://jscompress.com/ to minify code once it is running correctly. Why do you not use local storage for synchronizing across tabs and browser windows? I do not think cookies will work for this purpose. You do not need to use iframes to use local storage: they are totally independent code. Use jquery-idleTimeout.js or the minified code, jquery-idleTimeout.min.js, for tab/window synchronization with no iframe functionality. I hope I understand your question correctly.

AdvantmedKinjal commented 8 years ago

@JillElaine
Thanks for response. As mention above in my question My application works with multiple sub domain.Local storage create separate store for every domain even for sub domain also.And I want common storate for all domain.So i Use cookie instead of LocalStorage. I only add jquery-idleTimeout.min.js and store.js from source and even I change in this file not any error any any kind of problem regarding this.

JillElaine commented 8 years ago

I will try to help. It would be great to be able to synchronize tabs/windows across subdomains.

To debug your code, download & edit this script: https://github.com/JillElaine/jquery-idleTimeout/blob/master/jquery-idleTimeout-for-testing.js.

Edit this script with your 'cookie' changes. Then upload your modified script, jquery-idleTimeout-for-testing.js, to your test site, and observe the debug console.

For debugging, use Mozilla Firefox with the Firebug or similar debug tools on another browser. https://addons.mozilla.org/en-us/firefox/addon/firebug/ The jquery-idleTimeout-for-testing.js will print out many messages to the debug console.

Add or modify the "console.log('your console message here')" messages as you need. Then you can see why the change from localStorage to 'cookie' is not working.

Ask more questions if you need help. I will change the subject of your issue to be more clear.

JillElaine commented 8 years ago

After some review, I do not think it is possible to use 'cookies' to synchronize windows and tabs.

To allow localStorage to communicate across subdomains within the same parent domain, please try to 'relax' the 'same origin' policy. https://en.wikipedia.org/wiki/Same-origin_policy#Relaxing_the_same-origin_policy and https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy#Changing_origin

Hopefully you can find a solution to relax the same origin policy so that windows & tabs from your parent and subdomains can communicate via localStorage. There is no need to modify the jquery-idleTimeout script.