How to check if a file exists in Javascript?

  • 1
  • Question
  • Updated 8 years ago
  • Answered
Hello everyone.
I've been messing around with JQuery UI and I want to use some of the Highlight/Error boxes. What I'm wanting to do is make it appear when I'm working on the site, so it informs the user that editing is taking place, so they can expect changes to happen. What I thought I could do is make the Javascript run if a certain file exists somewhere, maybe in my Dropbox, and not run if it doesn't exist. So I could drop this file into my Dropbox, let it sync, and the popup will appear, and when I'm done, I can delete the file, and the box disappears.

Basically, what I'm trying to say is, how do I check if a file exists in Javascript?

Thanks Guys
Callum Booth
Photo of Callum

Callum

  • 357 Posts
  • 32 Reply Likes
  • happy

Posted 8 years ago

  • 1
Photo of Laura Thomas

Laura Thomas, Social Media Coordinator

  • 4536 Posts
  • 211 Reply Likes
Hi Callum,

This seems like a case of the student surpassing the instructor! We can't think of a way to accommodate your end goal of alerting users that your site is currently being edited, though this does sound like an interesting feature request for our Product team.

Sorry I don't have better input for you.
Photo of diane

diane

  • 1238 Posts
  • 121 Reply Likes
Hi, Callum,

If I'm understanding what you are trying to achieve correctly, this would not be possible with javascript. Javascript is client side programming and you would need something server side such as php or asp neither of which is possible with Yola.
Photo of Nathan

Nathan, Champion

  • 3739 Posts
  • 307 Reply Likes
<!--

Hi Callum! I have a good idea!

First, put this code in an HTML widget any where on the page:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/...>

<script type="text/javascript">
$(document).ready(function(){
jQuery.fn.fadeToggle = function(speed, easing, callback) {
return this.animate({opacity: 'toggle'}, speed, easing, callback);
};

$("#updating_toggler").click(function() {
$("#updating_alert").fadeToggle("slow");
});
});
</script>

<style type="text/css">
#updating_alert {

/*You can change this CSS*/

background-color:yellow;
border:2px solid orange;
padding:10px;
position:absolute;
top:0px;
left:5%;
}

#updating_toggler {
background-color:#6CD132;

border:0px;
height:25px;
}

</style>

<div id="updating_alert">

<font size="3"> We are updating our site right now! Expect changes soon!     </font><button type="button" id="updating_toggler"><font size="3" color="red" face="comic sans ms">X</font></button>

</div>

Now put this code at the VERY TOP of the page in it's own HTML widget:

<style type="text/css">

#updating_alert {
display:none;
}

</style>

Whenever you are updating your site, just change "none" to "block" Thats it! And I even made it where they can exit out of the box and it will fade away!

-->

Example page: Click here for example page
Photo of Callum

Callum

  • 357 Posts
  • 32 Reply Likes
Hi everyone,

Thanks for your help on this.

@Diane Could I maybe achieve it with Visual Basic? Something like 'If System.IO.File.Exists("thefile.txt") Then' and then incorporate the Javascript into it somehow?

@Nathan Thanks, I'm definitely going to try that! Thanks :)
Photo of Nathan

Nathan, Champion

  • 3739 Posts
  • 307 Reply Likes
Hi Callum, I also made it were when they click the X it fades away! Thats done wit JQuery.
Photo of Callum

Callum

  • 357 Posts
  • 32 Reply Likes
Thanks Nathan! I'm gonna try adding it to my site now! :D
Photo of Nathan

Nathan, Champion

  • 3739 Posts
  • 307 Reply Likes
Ok, did you see the example page too? I will think of a way to make it where you can have the file in and just delete it when you're done.
Photo of Callum

Callum

  • 357 Posts
  • 32 Reply Likes
I did see the example page, and thanks for the effort, it's working great,I'm just getting a test page ready so I can experiment with it, Thanks again!
Photo of Nathan

Nathan, Champion

  • 3739 Posts
  • 307 Reply Likes
No problem! Rapi-tweet rocks! I am going to use it for the first time right now!
Photo of Callum

Callum

  • 357 Posts
  • 32 Reply Likes
Hey Nathan,
Just commenting to let you know that, that code is AWESOME! Here's the test page: http://rapitweet.co.uk/test.php I tweaked it a bit, but it works great! :D
Photo of Nathan

Nathan, Champion

  • 3739 Posts
  • 307 Reply Likes
Yeah, it looks better than what I had! I'm glad you like it! :) You put in border-radius and an image instead of that button! Looks great! Your site rocks!
Photo of Callum

Callum

  • 357 Posts
  • 32 Reply Likes
Thanks Nathan! :D Thats just made my day!
Photo of diane

diane

  • 1238 Posts
  • 121 Reply Likes
Callum, to answer your question, VB is not allowed with Yola.

Nice solution, Nathan!