简体   繁体   English

检查文件是否存在,如果不创建,则为Javascript

[英]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. 我目前仅在网站上使用HTML / CSS / JS。 Later this should run on an apache or IIS server. 稍后,它应在apache或IIS服务器上运行。

Situation : On my website I wish user to access different servers. 情况:在我的网站上,我希望用户访问其他服务器。 I got a html select with a lot of choice. 我有很多选择的HTML选择。 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. 他们做出选择并单击“连接”按钮后,我会检查他们做出的选择,然后在新标签页的链接中打开它(如127.0.0.1这样的Web界面)。

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 示例:如果某人使用了127.0.0.1,则任何人都不应访问128.0.0.1或129.0.0.1

The solution I found was creating a file when someone access 127.0.0.1. 我发现的解决方案是当有人访问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. 因此,当有人要访问128.0.0.1或129.0.0.1时,我检查文件是否存在。 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. 事先感谢您的帮助,我只是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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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