Javascript不适用于Chrome扩展程序

时间:2018-11-21 15:40:58

标签: javascript html google-chrome

我制作了一个html文件用作chrome扩展名。 如果我打开html文件,一切正常。但是当我上传扩展程序时,按钮不起作用。

HTML:

                        <button onclick="generate()">Generate</button>
                        <button onclick="copyPassword()">Copy</button>

Javascript:

//generate random password
function generate(){
    //set password length
    let complexity = document.getElementById("slider").value;

    //possible characters
    let values = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW0123456789`~!@#$%^&*()_-+=][{}':;><,./?\|";

    let password = "";

    //create for loop to choose password characters
    for(var i = 0; i <= complexity; i++){
        password = password + values.charAt(Math.floor(Math.random() * Math.floor(values.length - 1)));
    }

    //add password to textbox
    document.getElementById("display").value = password;

    //add password to previously passwords section
    document.getElementById("lastNums").innerHTML += password + "<br />";
}

//set default length display of 25
document.getElementById("length").innerHTML = "Length: 25";

//function to set length based on slider position
document.getElementById("slider").oninput = function(){
    if(document.getElementById("slider").value > 0){
        document.getElementById("length").innerHTML = "Length: " + document.getElementById("slider").value;
    }
    else {
        document.getElementById("length").innerHTML = "Length: 1";
    }
}

//function to copy password
function copyPassword(){
    document.getElementById("display").select();

    document.execCommand("Copy");
}

感谢您的帮助。

~~ BE

0 个答案:

没有答案