Skip to content
forked from jitbit/TabUtils

Multiple browser tabs communication, locking and synchronization

License

Notifications You must be signed in to change notification settings

jzlingmo/TabUtils

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

TabUtils

Multiple browser tabs communication, locking and synchronization component. Based on localStorage object.

Features:

  • executing "interlocked" function call - runs only once per multiple tabs
  • broadcasting a message to all tabs (including the current one) along with some message "data" string
  • handling a "broadcasted message" event

Usage

<script src="TabUtils.js"></script>

<script>

//interlocked call - runs code only once
TabUtils.CallOnce("lockname", function () { alert("I run only once in multiple tabs"); });

//handle a broadcasted message
TabUtils.OnBroadcastMessage("eventName", function (eventDataString) { DoSomething(); });

//sends a broadcast message to all tabs, including the current tab too!
TabUtils.BroadcastMessageToAllTabs("eventName", eventDataString);

//P.S. standard localStorage events are not sent to current tab, only OTHER tabs.
//This component sends the message to ALL tabs

</script>

Make sure you register the event handler BEFORE sending a broadcasted message.

Contributions are very welcome.

Dependencies: jQuery

About

Multiple browser tabs communication, locking and synchronization

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%