0

Is it possible for me to pass a variable from my popup.js and use it globally in my content script? I need to be able to pass a variable from the popup and use it in my content script as a variable. I've tried all sorts of answers but I'm still stuck.

Below is a code snippet where I would have to use the user input assigned to minNum:

if (checkPage() == true) {
        if (num <= minNum) {
            console.log('Leaving call.');
            leaveCall();
        }
    }

Below are my popup.js and popup.html file that just adds or reduces variable people:

people = 3;

document.addEventListener(
    'DOMContentLoaded',
    function () {
        var addButton = document.getElementById('add');
        var reduceButton = document.getElementById('reduce');

        addButton.addEventListener(
            'click',
            function () {
                people += 1;
                document.getElementById('minNum').innerHTML = people;
            },
            false
        );
        reduceButton.addEventListener(
            'click',
            function () {
                people -= 1;
                document.getElementById('minNum').innerHTML = people;
            },
            false
        );
    },
    false
);
<!DOCTYPE html>
<html>

<head>
  <title>Yeet Meet</title>
</head>

<body>
  <h1 id="minNum">3</h1>
  <button id="add">+</button>
  <button id="reduce">-</button>
  <script src="popup.js"></script>
</body>

</html>

I want to pass variable people to my content script so that I could assign it to minNum.

I apologize if this has already been answered and it probably just flew over my head but I can't seem to make anything work. Thank you for your help.

0 Answers0