javascript - Mozilla Extension: Multiple States between multiple tabs -


i creating mozilla extension converts content of webpage on click of "convert button"(label: convert) in other language , label gets converted english on click of button(label: english) content gets converted original form

enter image description here

enter image description here

i tried set attribute "changedcontent" each tab on event focus ,focussed tab reads "changedcontent" attribute , set label on button ("convert" or "english")

problem arises need switch between multiple tabs, plugin in different tab should maintain different state depending on whether displaying changed content(should display button label: english) or in original form(should display button label: "convert")

so when click refresh button or click other link in webpage. label of button "english" converted content on page should gets changed "convert" have handled page unload event track page refresh or link click, since webpage may contain multiple frames/iframes event getting called multiple times. if in meantime switch tab, label of other tab gets converted "english" "convert"

code of unload event is:

window.addeventlistener('unload', unloadingdocument, true); function unloadingdocument() {      var currenttab = gbrowser.selectedtab;     currenttab.setattribute("changedcontent" , "false");//set transliterated attribute false     var convertbutton = document.getelementbyid("convert_button");     convertbutton.setattribute("label","convert"); } 

please suggest how can solve problem , maintain different states of mozilla plugin between multiple tabs.

thanks

you use session store api have independent state between tabs.

-- edit:

so if have way know if specific tab "translated or not", if want button change have correct state when tab selected, might want check tabselect event: detecting tab selection in event check tab attribute check if have change or not label/behaviour of button.

-- edit 2 :

if when click "convert" button processing, , set attribute changedcontent of tab true. have load/unload listener check refresh, change state false. if change tabs, have tabselect event change button whenever change tabs.

if add listener when change changedcontent true. when event beforeunload first called, check if changedcontent true, change false , remove listener.


Comments