2016-06-22 6 views
0

에 액세스하고 싶습니다. 내 manfiest.json은이 위치입니다.Chrome 확장 프로그램의 로컬 저장소

{ 
    "manifest_version": 2, 

    "name": "GTmetrix Analyzer Plugin", 
    "description": "This extension will analyze a page using GTmetrix", 
    "version": "2.1", 
    "options_page": "options.html", 
    "browser_action": { 
    "default_icon": "icon.png", 
    "default_popup": "popup.html" 
    }, 
    "background": { 
    "scripts": ["background.js"], 
    "persistent": false 
    }, 
    "permissions": ["tabs", "storage"], 
    "content_scripts": [ 
     { 
      "matches": ["http://ticketchest.geekschicagolabs.com/admin/orderHistory"], 
      "css": ["mystyles.css"], 
      "js": ["jqueryui-min.js", "content-script.js"] 
     } 
    ] 
} 

내 popup.html이

<!doctype html> 
<html> 
    <head> 
    <title>Ticket chest</title> 
    <script src="popup.js"></script> 
    </head> 
    <body> 
    <h1>Ticket chest extension</h1> 
    <a href="options.html">Settings</a> 
    <!-- <button id="checkPage">Check this page now!</button> --> 
    </body> 
</html> 

하고 background.js는

chrome.runtime.onMessage.addListener(function(response, sender, sendResponse){ 
localStorage['privateKeyy'] = response; 
}); 

지금 나는 그것이 또한 수의 로컬 저장소에 저장됩니다 어떤 사용자가 텍스트 영역에 입력 할 것입니다 extenison의 로컬 저장소가있는 웹은 확장 로컬 저장소에 저장되지만 웹 페이지에는 저장되지 않습니다.

하고 (대신 확장의 배경 스크립트 코드를 (전용) 실행의) 콘텐츠 스크립트 코드를 이동 웹 페이지의 로컬 스토리지에 데이터를 저장하고자하는 경우 그 내용 스크립트 코드

window.onload = function() { 

    document.getElementById('save').onclick = function(){ 
    var privateKey = document.getElementById("textarea").value; 

    chrome.storage.sync.set({'privateKey':privateKey}, function(){ 
    //document.getElementById('privateKey').value = privateKey; 
    //chrome.browserAction.setBadgeBackgroundColor({color:[200, 0, 0, 100]}); 
    //chrome.tabs.sendMessage(privateKey); 
    chrome.storage.local.set({'privateKeyy':privateKey}); 
    localStorage.setItem("lastname", "Smith"); 
    alert('save successfully'); 
    }); 
    //syncStorage["privateKey"] = privateKey; 
    } 

    document.getElementById('erase').onclick = function(){ 
    chrome.storage.sync.remove('privateKey', function(){ 
    alert('erase successfully'); 
    }); 
    } 

    document.getElementById('get').onclick = function(){ 
    chrome.storage.sync.get('privateKey', function(data){ 
    alert(data.privateKey); 
    console.log(data.privateKey); 
    }); 
    } 

} 
+3

PHP와 관련이 있습니까? – Farkie

+0

https://developer.chrome.com/extensions/storage – Farkie

+0

@Farkie 나는이 링크를 따라 간다. 잘못된 키가 웹 페이지의 로컬 저장소에 저장되지 않는다 ... – hu7sy

답변

2

입니다 . 여기를 참조하십시오 : https://stackoverflow.com/a/23082216/4419582

+0

여전히 확장 로컬 저장소에 키를 저장합니다 – hu7sy

+0

특히 'content-script.js'코드를 더 제공 할 수 있습니까? 방금 내 로컬 스크립트에서'localStorage.setItem ("key", "value");를 실행했는데 현재 열어 둔 웹 페이지의 로컬 저장소에 (Chromium의 개발자 도구를 사용하여) 저장 한 것을 볼 수 있습니다. 확장 프로그램의 로컬 저장소에 데이터가 없습니다. – jengeb

+0

나는 js 코드를 업데이트했지만, 내용 스크립트로 옮겼습니다. – hu7sy

관련 문제