I am wanting to minimize a google chrome extension pop up window when a button is clicked .
So far I have tried the following
adding onclick = "window.close();" to the tags of the link.
Also,
document.getElemenetById('minimizewindow').onclick = function () {
return window.close();
};
CodePudding user response:
Are you refering to the menu of the extension or a real in Browser pop-up? Im assuming here you ment the menu:
You can only close things with Window.close()
which are opened with Window.open()
.
Reference for Window.close(): https://developer.mozilla.org/en-US/docs/Web/API/Window/close?retiredLocale=de
There is a chance that you cant controll the extension at all. Because chrome protects them for sure. Imagine you try to execute malicious code and it can just controll the Browser extensions.
Here is also a far related question in StackExchange: https://security.stackexchange.com/questions/193701/is-it-possible-for-page-to-get-your-installed-extensions-through-javascript
I know the answer fits not 100% but is better than probably no one. Could you comment if this helps you? So if not I can also delete it.
CodePudding user response:
It is possible to close the popup with window.close()
.
I understand the documentation says it can't be done.
Window.close()
Below is a sample that closes a popup.
manifest.json
{
"name": "hoge",
"version": "1.0",
"manifest_version": 3,
"action": {
"default_popup": "popup.html"
}
}
popup.html
<html>
<body>
<button id="close">Close</button>
<script src="popup.js"></script>
</body>
</html>
popup.js
document.getElementById("close").onclick = () => {
window.close();
}