Chrome Extension: Remembering a checkbox value when popup is reopened

前端 未结 3 1919
醉酒成梦
醉酒成梦 2020-12-20 01:49

Newbie here so sorry if this is pretty elementary. I\'m making an extension that simply has a checkbox/switch when loaded. It is to be unchecked the first time you open it b

3条回答
  •  心在旅途
    2020-12-20 02:13

    Deleted my previous response because I see where I went wrong again, code I used is below

    function restoreOptions() {
        chrome.storage.sync.get({
            //False is the default value when first opening the extension
            'initialValue' : false
        }, function (items) {
            document.getElementById('notification').checked = items.initialValue;
        });
    }
    

    Pretty much exactly what was suggested, as well as what was in the google options page (I did read it but just didn't get it at the time). I missed the bit where the 'initialValue' was set to false if storage didn't have a value which fixed my issue for when I launched the extension for the first time.

    It's all prefectly clear now, finally. Thanks again for your help

提交回复
热议问题