0

I have a problem with creating a simple chrome extension.

Following should this program do on the options page:

  • User have to enter two values (apikey and apisecure) These values will be saved on local storage.

I want to get these storaged values and print them out on options.html:

<html>
<head>
    <title>API-Konfiguration</title>
    <script type="text/javascript" src="options.js"></script>
</head>
<body onload="loadOptions()">
    <h1>Bitte API-Key und API-Secure hinterlegen:</h1>
    <form>
API-Key:<br>
<input type="text" id="v_apikey" name="apikey">
<br>
API-Secure:<br>
<input type="text" id="v_apisecure" name="apisecure">
</form>
    <br />
    <button onclick="saveOptions()">Speichern</button>
    <br />
    <button onclick="eraseOptions()">Daten loeschen</button>
</body>
</html>

The options.js contains following:

function loadOptions() {
    var apikey = localStorage["v_apikey"];
    var apisecure = localStorage["v_apisecure"];

}

function saveOptions() {
    var apikey = document.getElementById("v_apikey");
    var apisecure = document.getElementById("v_apisecure");
    localStorage["v_apikey"] = apikey;
    localStorage["v_apisecure"] = apisecure;
}

function eraseOptions() {
    localStorage.removeItem("v_apikey");
    localStorage.removeItem("v_apisecure");
    location.reload();
}

function getItems() {

document.write(localStorage.getItems("v_apikey"));
document.write(localStorage.getItems("v_apisecure"));

}

I don't know how to output the saved values in the input field (If they have already been stored).

Who can help me with this "little" problem?

Thanks in advance!

1 Answer 1

1

To save values to the localstorage, you can also use below:

window.localStorage.setItem("newsrefreshcomment", value);

Below is the sample code that i have used to retreive the value from local storage.Before retreving value from local storage,we have to check for web storage support.

To retreive the value stored,we can use:

if (typeof (Storage) != "undefined") {
        if (localStorage.getItem("newsrefreshcomment") != null) {
            commentValnews = localStorage.getItem("newsrefreshcomment").toString();

        } 
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.