简体   繁体   中英

Check if a file exists, if not create one, Javascript

I know this question have already been asked. BUT NONE of this , this , this , this , this or this solutions worked for me. I'm only using HTML / CSS / JS for the moment on my website. Later this should run on an apache or IIS server.

Situation : On my website I wish user to access different servers. I got a html select with a lot of choice. Once they made their choice and click on connection button I check the choice they made and open it (it's a web interface like 127.0.0.1) in a new tab the link.

Problem : Some of the servers should not being accesssed if one is already used. Example : If 127.0.0.1 is used by someone, no one should access 128.0.0.1 or 129.0.0.1

The solution I found was creating a file when someone access 127.0.0.1. So when someone want to access 128.0.0.1 or 129.0.0.1, I check if the file exists. If it does exists I don't open the link and show an alert, if it does not exist I create it and open the link in new tab.

Another problem : How can I know when the tab will be closed in order to delete the file ? Have you got another solution to this problem ?

Thx in advance for helping me, I'm just a beginner in web. No solutions worked for me so far ...

This code help you to detect when user close a tab.

<script>
   window.onbeforeunload = function () {

     //write your code here 

     return false;
   };
<script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM