|
| 1 | +--- |
| 2 | +title: "Window Open Features: Restrict and Test" |
| 3 | +layout: post |
| 4 | +published: true |
| 5 | +date: 2020-03-05 08:33:11 +0100 |
| 6 | +categories: |
| 7 | + - administration |
| 8 | + - config |
| 9 | + - howto |
| 10 | + - javascript |
| 11 | + - html |
| 12 | + - programming |
| 13 | + - software |
| 14 | + - website |
| 15 | + - web |
| 16 | +tags: |
| 17 | + - javascript |
| 18 | + - mozilla |
| 19 | + - demo |
| 20 | + - config |
| 21 | + - firefox |
| 22 | + - programming |
| 23 | + - trick |
| 24 | + - userinteraction |
| 25 | + - web |
| 26 | +--- |
| 27 | + |
| 28 | +Are you also annoyed by websites that open popups and external windows without your menu bar? And without scrollbars and no close button and ... and .. and.. |
| 29 | + |
| 30 | +## Restrict Window Open Features |
| 31 | + |
| 32 | +Don't worry, you can disable these "features"! |
| 33 | +In Firefox, open [about:config](about:config) and search for `dom.disable_window_open_feature` (see [@azure's pleroma post](https://pleroma.site/notice/9sfjyFYxWIdEMexkYa)). |
| 34 | +Full documentation on these settings are available through [MozillaZine](http://kb.mozillazine.org/Prevent_websites_from_disabling_new_window_features). |
| 35 | +These preferences can also be [set (and locked) system wide](kb.mozillazine.org/Locking_preferences), which may be useful for multi-user and multi-system environments |
| 36 | + |
| 37 | + |
| 38 | +## Test Window Open Features |
| 39 | + |
| 40 | +[Mozilla's Developer portal has a documentation on possible Window Open Features](https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Window_features). |
| 41 | +There you can learn which features are available, what they mean, and how to set them. |
| 42 | + |
| 43 | +Testing is then pretty easy. |
| 44 | +The following checkboxes allow for enabling/disabling most useful window features. |
| 45 | +If a box is ticked, the corresponding feature will be set; if it's unticked the feature will be turned off. |
| 46 | +You can then click the link below to test how your browser behaves when opening this blog using the chosen set of features. |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +<ul id="settings"> |
| 51 | +</ul> |
| 52 | + |
| 53 | +<script type="text/javascript"> |
| 54 | + var ul = document.getElementById("settings"); |
| 55 | + var windowRef = null; |
| 56 | + var settings = { |
| 57 | + "menubar": "Menu Bar", |
| 58 | + "toolbar": "Navigation Toolbar (Back, Forward, Reload, Stop...)", |
| 59 | + "scrollbars": "Scroll Bars", |
| 60 | + "resizable": "Resizable", |
| 61 | + "status": "Status Bar", |
| 62 | + "personalbar": "Personal Toolbar / Bookmarks / Site Navigation Ba", |
| 63 | + "location": "Location Bar", |
| 64 | + "fullscreen": "Open in Fullscreen (not implemented in many browsers)", |
| 65 | + } |
| 66 | + |
| 67 | + for (const [key, value] of Object.entries(settings)) { |
| 68 | + var input = document.createElement("input"); |
| 69 | + input.type = "checkbox"; |
| 70 | + input.name = key; |
| 71 | + input.value = key; |
| 72 | + input.id = key; |
| 73 | + |
| 74 | + var label = document.createElement('label') |
| 75 | + label.htmlFor = key; |
| 76 | + label.appendChild(document.createTextNode("\u00A0" + value)); |
| 77 | + |
| 78 | + var li = document.createElement("li"); |
| 79 | + li.appendChild(input); |
| 80 | + li.appendChild(label); |
| 81 | + |
| 82 | + ul.appendChild(li); |
| 83 | + } |
| 84 | + |
| 85 | + function openPopup () { |
| 86 | + var winFeatures = "" |
| 87 | + |
| 88 | + for (const [key, value] of Object.entries(settings)) { |
| 89 | + var input = document.getElementById(key); |
| 90 | + if (input.checked) |
| 91 | + winFeatures += key + "=yes," |
| 92 | + else |
| 93 | + winFeatures += key + "=no," |
| 94 | + } |
| 95 | + |
| 96 | + if(windowRef == null || windowRef.closed) { |
| 97 | + windowRef = window.open("https://binfalse.de/?test=window_open_feature", "Popup", winFeatures); |
| 98 | + } else { |
| 99 | + alert ("Popup already opened!? Please close it to test again."); |
| 100 | + } |
| 101 | + } |
| 102 | +</script> |
| 103 | + |
| 104 | +**TEST NOW:** <a href="https://binfalse.de/?test=window_open_feature" target="Popup" onclick="openPopup(); return false;">Open binfalse.de using above settings.</a> |
| 105 | + |
| 106 | +The test should be browser independent, you just need to have Javascript enabled. |
| 107 | +However, let me know if it doesn't work for you! |
| 108 | + |
| 109 | +To see how I implemented the test tool take a look into the source code of this page, or [check the script on GitHub](https://github.com/binfalse/binfalse.de/blob/master/_posts/2020-03-05-testing-window-open-features.md). |
| 110 | +Remember? This blog is all open source :) |
0 commit comments