Reputation: 264
For a webapp, I have an option to open a popup (w = window.open
) to enable multiscreen for enduser.
When the popup is opened by js without user input (loading previous user configuration), Firefox block it as expected.
I can detect it with w == null
and handle this to have a functional application without the popup if the user doesn't want them.
However, if the user click the "Allow this site to open popups", then Firefox open a popup containing the current page.
Is there a possibility to prevent Firefox from opening blocked popup ?
Edit: MWE
<html>
<body>
<script type="text/javascript">
function bug () {
let w = window.open('', '', 'width=800, height=600');
if (w == null) {
console.log("blocked");
return;
}
let p = w.document.createElement('div');
p.className += "layout";
let c = w.document.createElement('div');
c.className += "content";
c.style.height = '100%';
c.innerHTML = "Hello world !";
w.document.body.appendChild(p);
p.appendChild(c);
}
document.body.innerHTML = "Hello fellow human beings";
bug();
</script>
</body>
</html>
Edit2 : The mix of current page and popup was on my side, the main problem still persists.
Thanks
Upvotes: 0
Views: 572
Reputation: 769
If the user chooses to open the popup from the popup blocked toolbar after it has been blocked, it will load the URL you give to window.open
. You haven't given one, so it'll the default to the same page.
First, and the usual, solution is to have the popup load a different page instead of letting it load the same page and then trying to modify it's DOM. Then opening the blocked popup after the fact will still load the correct page with different content.
Second solution to do more closely what you asked for, is to set the popup URL to a page which will just close itself immediately. In the good case of not getting blocked you can stop the loading of that page before it loads to close itself.
Upvotes: 1