First, there is a tag h1
unopened.
Another problem is that your manifest is incorrect. Instead of popup
, utilize default_popup
:
{
"name": "RandomHype",
"version": "1.0",
"manifest_version": 2,
"description": "RandomHype official Extensions.",
"browser_action": {
"default_popup": "rh.html"
}
}
Continuing, if your intention is to change the content of <p id="doThing">...</p>
with a predefined value each time script is executed, you need to put this script after the element.
Opening the console, you will see the following error:
Typeerror: Document.getElementById(...) is null
This is because inside the <head>
, specifically on that line document.getElementById('doThing')
you try to get an element that has not yet exists was loaded.
You can...
Place this script at the end of the document before closing the tag <body
:
<html>
<head>
<link rel="stylesheet" href="typeget.css">
</head>
<body>
<center>
<h3>I should</h3>
<br>
<h1><p id="doThing">Code</p></h1>
</center>
<script>
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
var randomVals = ['Play BTD5',
'Code',
'Watch a video',
'Play Chess',
'Study',
'Chat (Skype)',
'Check Twitter',
'Check the news on Tecmundo',
'Talk about SW'
];
var r_i = getRandomInt(0, randomVals.length - 1);
document.getElementById('doThing').innerHTML = randomVals[r_i];
</script>
</body>
</html>
Run the script when the GIFT be ready:
<html>
<head>
<link rel="stylesheet" href="typeget.css">
<script>
document.addEventListener('DOMContentLoaded', function() {
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
var randomVals = ['Play BTD5',
'Code',
'Watch a video',
'Play Chess',
'Study',
'Chat (Skype)',
'Check Twitter',
'Check the news on Tecmundo',
'Talk about SW'
];
var r_i = getRandomInt(0, randomVals.length - 1);
document.getElementById('doThing').innerHTML = randomVals[r_i];
}, false);
</script>
</head>
<body>
<center>
<h3>I should</h3>
<br>
<h1><p id="doThing">Code</p></h1>
</center>
</body>
</html>
More information on the DOMContentLoaded
at that link.
These examples were to rotate the snippet, in Chrome extensions the Javascript file should be created part and not inline in the HTML document. Create a file popup.js
(for example), put your Javascript code in it and only refer to HTML:
<script src='popup.js'></script>
The ideal is you put here your code without us having to go to another site to see it. You can use the Snippet Stack using the "JS/HTML/CSS Snippet" button in the edit bar. Nor can you ask us to review all your code looking for the error. What goes wrong? What did you try to fix? Debug (
console.log
)?– brasofilo
Sorry, I’m pretty new here.
– MucaP
It went wrong: The extension is added, but Popup does not open when I click. What I tried: Change something from HTML and . json but could not.
– MucaP
It’s getting better :) I imagine that the first part is the Manifest and the second is the popup
rh.html
.... is that it? If you can also explain what your extension does it would be cool.– brasofilo
Yes, My extension simply randomizes a word between one of those words and displays.
– MucaP