I have a chrome extension that has two buttons from the HTML file.
I use getElementByID('button_name')
and addEventListener('click', function(){});
The function is in the javascript file and tries to access and print a global JSON.stringify()
object.
I used an alert and it says: chrome-extension://"something"/popup.html
.
I tried to declare a var outside the function then initialize it inside, but it did not work. I tried many alerts()
to try to see the object and see if I can access it, but the only thing that worked so far was a String
, I'm guessing because it is not as complex as an object.
popup.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<button id="list">Missing videos for this page</button>
<button id="reset">Clear List</button>
<script type="text/javascript" src="popup.js"></script>
<script type="text/javascript" src="content.js"></script>
</body>
</html>
content.js
//far up
const url = window.location.href;
var delString = JSON.stringify([url, "delete"]);
//html button
var reset = document.getElementById('reset');
if(reset){
reset.addEventListener('click', function(){
alert(window.location.href); // gives chrome-extension:// not url
alert(JSON.parse(delString)); // gives the array, but url is same as above.
//myStorage.setItem(delString, "");
});
}