Wikipedia:Reference desk/Archives/Computing/2017 October 21

Computing desk
< October 20 << Sep | October | Nov >> October 22 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


October 21

edit

Is there an IP address that will just close the current browser tab ?

edit

I've blacklisted certain ad sites in my Windows 7 hosts file, by redirecting those sites to 127.0.0.1, but they still pop up a blank tab or window that says "Site not found", which I then have to close. So, can I instead redirect them to an IP address that just closes the current browser tab ? If it's possible, you would think somebody would have set up such a site. I could, of course, set up my own web server on my PC, but that's more trouble than it seems like such a simple task should require. BTW, here's the JavaScript to close the current tab, and if that server ran this file, I think it would work:

<script>
   function closeWindow() {
       window.open(,'_parent',);
       window.close();
   }
</script> 
<body onload="closeWindow()">

StuRat (talk) 23:49, 21 October 2017 (UTC)[reply]

I don't know of any website that specifically does this, but you could probably run your script with Greasemonkey; failing that, w3schools.com has a page where you can execute small script files, and that might work (I don't know Javascript well enough to judge). OldTimeNESter (talk) 00:16, 23 October 2017 (UTC)[reply]
I already ran it by creating the file on my desktop and clicking on it. It did indeed open it's own tab in my browser, then immediately close it, as it's supposed to do. However, to get this script to run when an ad site wants to pop up, I'd need the hosts file to redirect it to an IP address that runs this script. StuRat (talk) 00:28, 23 October 2017 (UTC)[reply]