In the options of my chrome extension I'd like to autofill a form field when the options page is opened. I have some code for this in the option.js file but it doesn't seem to autofill on opening.
I've tried some code which I will attach.
function() {
var randomString = function(length) {
var text = "";
var possible = "0123456789";
for(var i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
// random string length
var random = randomString(10);
// insert random string to the field
var elem = document.getElementById("email").value = random;
}();
I'm using the 'email' form field for the moment to test the code - I would create a new form field once the code works.
Aucun commentaire:
Enregistrer un commentaire