How can I add a panel with buttons to the beginning of body using js. The panel will be added to all sites. In manifest.json I have all_urls
Asked
Active
Viewed 271 times
0
-
Could you show us some relevant pieces of your code? We can't really help with the current information given by you. – Amit Beckenstein Jan 29 '20 at 19:09
1 Answers
0
To add buttons to a html page with plain javascript, you can do it like that:
//creates a panel
function createPanel(){
let panel = document.createElement("div"); //your panel element
panel.setAttribute("class","panelClass"); //define an css class for styling
panel.setAttribute("id","panelId"); //give the element an ID for better dom selection
document.body.prepend(panel); //add your panel before all other elements to the body
}
/**
* creates button
* elementId : id of the element where you want to append the button
*/
function addButtonToElement(elementId){
let elementToAddButton = document.getElementById(elementId); //element you want to append your button
let button = document.createElement("button"); //create new button dom element
let buttonText = document.createTextNode("New Button"); //create a text element
button.appendChild(buttonText); //adds the text element to the button
elementToAddButton.appendChild(button)
}
createPanel()
addButtonToElement("panelId")
Usefull links:

Tos
- 11
- 4
-
Can I insert another document before the html tag with my styles? – Oleg Romanovich Jan 30 '20 at 06:51
-
Can you specify "another document"? Do you mean a new html file or a external css for your styles? – Tos Jan 30 '20 at 14:51
-