Tuesday 15 June 2010

html5 - Is it possible to get access to my chrome extension localStorage from my website? -


I have created a Chrome extension that allows local storage from the background page (using chrome.storage.sync) Saves. Set ).

Now, say, I want to create a website and access the data of the extension on the local storage from the website, is it possible to access this data from this website domain? Maybe I can add something to the manifest file to allow that?

I here assume that you know the passage of the content between the content script and the background script Message for

Strong>

Content Script If the website has your website to open a site, then know that www.yourwebsite.com

  if (currentUrl == "www.yourwebsite .com ") {....}   

If this is your website, then drag the required data from the background script

  if (currentUrl ==" Www.yourwebsite.com ") {Chrome Exte Nsion.sendRequest ({"getLocalStorage Data": True, "dataFieldName": "Favorite Collar"}, handleLocalStorageResult;); } Function handleLocalstoosing Roustalting (Data Values) {.....}   

To get data in the handle, change the locale, insert the data into the HTML of the page so that your website's JavaScript can read it

  if (currentUrl == "www.yourwebsite.com") {chrome.extension.sendRequest ({"getLocalStorageData": true, "dataFieldName": "favorablecolor"}, handleLocalStorageResult); } Function handleLocalstageRelitt (data value) {var localStorageDataDiv = $ ('
'). Annex ('body'); LocalStorageDataDiv.attr ('ID', 'ExtensionData'); LocalStorageDataDiv.html (dataValue);

Your website's JavaScript

can now read the javascript data for your website

  var data = $ ('# ExtensionData') HTML () .; Alert ('My Extension's Local Storage Data' data);    

No comments:

Post a Comment