javascript - chrome extension: saving data attribute in background from popup -
background.js
function getframe() { // popup.js can access background's frame function return $('iframe')[0]; } function updatestatus(status) { // popup.js should call function update frame's status var frame = $('iframe')[0]; $(frame).data('status', status); }
popup.js
..dom ready var bg = chrome.extension.getbackgroundpage(); ('.hello').click(function () { bg.updatestatus('ready') } // <assume above event has been triggered here> var frame = bg.getframe(); console.log($(frame).data('status')) // undefined <- however, result
i trying store status in background's frame retrieve when popup re-opens. however, above result. explain why happening? missing data
attributes?
i figured out solution. instead of retrieving frame
element popup
, had following:
background.js
function getstatus() { // popup.js must retrieve current status way // $(bg.getframe()).data('status') bad var frame = $('iframe')[0]; return $(frame).data('status'); }
could add why happening?
Comments
Post a Comment