如何在 chrome 扩展中保存值?

问题描述

我想知道如何在 chrome 扩展中保存用户提供的输入。我已经看到了同一问题的其他答案,但我知道为什么但我不能这样做,所以请不要用 chrome storage api 链接回答,如果你能用适合我的代码的 chrome storage 链接回复,谢谢。这是html:

     <input type="text" id="html_whook" class="input_whook" placeholder="Webhook">
     <script src="./storage.js"></script>```


this is the js code,i was trying to do it:



window.onload = function() {
    function saveChanges () {
        let valore = document.getElementById('html_whook').value;

        chrome.storage.sync.set({'html_whook': valore},function() {
            alert(valore);
        });
        
    };
}

解决方法

我有点修复了我的代码,现在看起来像这样,我也更改了 html,控制台上也没有任何错误,但它仍然不起作用

        let valore = document.getElementById('discord_id').value;

        chrome.storage.sync.set({'discord_id': valore},function() {
            alert(valore);
        });
        
    };


html:    ```    <img src="LOGOVERO.png" class="image" alt="logo">
        <h1 class="testo">Enter your key:</h1>
        <p><input type="text" class="rounded-input" id="key" placeholder="XXXX-XXXX-XXXX-XXXX"></input></p>
        <h1 class="testo2">Enter your Discord ID:</h1>
        <p><input type="text" class="rounded-input2" id="discord_id" placeholder="Example#0001"></input></p>
    </style>
        <p><a><button class="btn" id="save">AUTHENTICATE</a></p>

    </body> This is just a part of the html```

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...