2015-01-04 3 views
0

옵션 메뉴에 대해 ~ settings.html ~을 크롬 확장으로 빌드하고 옵션 페이지에 ~ option.js ~를 사용하여 닫을 로직을 설정했습니다. 저장 버튼이 제출되면 옵션 팝업. 그러나 예기치 않게 그것은 한 번 일했습니다. 코드를 첨부하여 당신의 wisedom 도와주세요.크롬 확장 옵션 메뉴를 닫을 수 없습니다.

{ //manifest.json 
"name": "Demo Mode", 
"version": "1.0", 
"description": "A plugin todo something.", 
"icons": {"16":"images/logo16x16.png", 
    "48":"images/logo48x48.png" 

}, 
"permissions": ["declarativeWebRequest", "storage", "<all_urls>"], 
"options_page": "settings.html", 
"background": { 
    "scripts": ["background.js"], 
    "persistent": true 
}, 
"options_ui": { 
    "chrome_style": true, 
    "page": "settings.html" 
}, 
"manifest_version": 3, 
"browser_action": { 

    "default_icon": { 
     "19": "images/logo19x19.png", 
     "38": "images/logo38x38.png" 
    }, 

    "default_title": "Plugin", 
    "default_popup": "settings.html" 

} 
} 

options.js

// Saves options to chrome.storage 
function save_options() { 
    var server_setting = document.getElementById('server-settings').value; 
    chrome.storage.sync.set({ 
    serverSetting: server_setting 
    }, function() { 
    // Update status to let user know options were saved. 
    var status = document.getElementById('status'); 
    status.textContent = "Your setting is saved" 
    setTimeout(function() { 
     status.textContent = ''; 
     chrome.extension.getBackgroundPage().chrome.runtime.reload(); 
     window.close(); 
    }, 1000); 
}); 
} 

// Restores select box and checkbox state using the preferences 
// stored in chrome.storage. 
function restore_options() { 
chrome.storage.sync.get({ 
    serverSetting: 'production' 
}, function(items) { 
    document.getElementById('server-settings').value = items.serverSetting; 
}); 
} 
document.addEventListener('DOMContentLoaded', restore_options); 
document.getElementById('save').addEventListener('click', save_options); 

settings.html는

<!DOCTYPE html> 
<html> 
<head><title>CMC Plugin Settings</title> 
<style> 
    .main-pane { 
     clear: both; 
     min-height: 40px; 
    } 

    .row { 
     display: block; 
     box-sizing: border-box; 
     padding: 10px 5px; 
    } 

    .right-align { 
     float: right; 
     margin-bottom: 20px; 
    } 

    #status{ 
     min-height: 22px; 
    } 

    #server-settings { 
     width: 100%; 
     margin-top: 10px; 
    } 
</style> 
</head> 
<body> 


<div class="main-pane"> 
<div class="row"> 
    <div class="main-pane"> 
     <label class="label">Set your environment - </label> 
     <select id="server-settings" style="width:100%;"> 
      <option value="production">Production</option> 
      <option value="local">Local Development</option> 
     </select> 

     <p id="status"></p> 
    </div> 
</div> 
<div class="row"> 
    <button id="save" class="right-align">Save</button> 
</div> 
</div> 


<script src="options.js"></script> 
</body> 
</html> 
+0

저장 버튼을 클릭하면 옵션 페이지가 잘 닫혔습니다. 당신이이 문제를 아직도 충족시키는 지 궁금합니다. – gui47

+0

처음으로 닫히지 만 팝업의 경우 닫히지 않으며 때로는 다시로드되지 않습니다. 어떤 생각? –

+0

'chrome.extension.getBackgroundPage(). chrome.runtime.reload();'어떤 종류의 가증스러운 작업입니까? 이것은 옵션 페이지에서 직접 사용할 수 있습니다. 그리고 그것은 당신의 문제에 책임이 있다고 생각합니다 (부모 확장이 다시로드되면 더 이상 페이지가 연결되지 않습니다). – Xan

답변

0

chrome.extension.getBackgroundPage().chrome.runtime.reload(); 

를 제거하여 그것을 해결

chrome.runtime.reload(); 
window.close(); 
관련 문제