Answer the question
In order to leave comments, you need to log in
Opening page links from a button does not work in my Chrome extension, how can I fix it?
I made an extension, when you click, a pop-up with a button pops up and when you click on the button, all links with a certain class that are on this page open. The problem is that the extension does not work with the page, that is, it does not open links from it, but opens links only within itself (from the popup.html file).
Here is the popup.html markup
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Index</title>
<script src="popup.js"></script>
</head>
<body>
<button id="btnScreens">Open Screens</button>
</body>
</html>
document.addEventListener('DOMContentLoaded', function() {
let openScreensBtn = document.getElementById('btnScreens');
openScreensBtn.addEventListener('click', function() {
let links = document.querySelectorAll('.link');
let arrLinks = Array.from(links);
let arrHref = [];
for (let i = 0; i < arrLinks.length; i++) {
arrHref.push(arrLinks[i].getAttribute('href'));
};
for (let i = 0; i < arrHref.length; i++) {
window.open(arrHref[i], '_blank');
};
});
});
{
"name": "Ext",
"description" : "",
"version": "1.0",
"manifest_version": 2,
"browser_action": {
"default_icon": "128.png",
"default_popup": "popup.html"
},
"permissions": [
"activeTab"
]
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question