Connect from popup.html to background.js script in Chrome Extension.
When I click on the button, I want the background script to open a new tab.
Background Script:
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if (message == "output") {
var win = window.open('https://www.google.ca/webhp?hl=en&sa=X&ved=0ahUKEwjesaKd26TcAhWNw4MKHcN-CwgQPAgD', '_blank');
win.focus();
}
});
HTML:
<body>
<script src="next.js"></script>
<input id="output" type="button" value="Go To Alternative Forum"/>
</body>
Next:
document.getElementById("output").addEventListener(("click"),function(){
chrome.runtime.sendMessage("output");
});