Re: Checking if a file exist



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In article <1130257921.185965.179080@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"batels" <batels@xxxxxxxxx> writes:
[...]
> Everything i use is local. I need to write an Html file (call it #1)
> that
> searches for a different html file (call it #2) that exist at them same
> directory. if it exist it creates a link to in,and if not i should
> execute a C file that will generate the #2 file.
>
> My probem is - i don;'t know how to search for a file (tryed
> JavaScript,didn't work) and how to execute a file from Html.

If I'm understanding you correctly, you basically can't do that.

I assume that what you want to do is:

1. When a page is loaded, a chunk of Javascript on the page looks to see
if other pages are available, and if they do create links to them
(this is doable, although quite hard);
2. If one of these pages doesn't exist, create it (this can't be done
the way you describe).

Remember that you don't have files. You have pages, which are given to you
by the server. The HTML is displayed by the browser, and any Javascript is
executed *on the browser* --- and it can't execute stuff on the server. All
it can do is to ask the server to do something (by getting a
specially-named page, or doing a POST) and the server does it from there.

You can do (1) by using something like XMLHTTPRequest to attempt to fetch a
web page. That'll let you see if it succeeds or not. I'd recommend against
it, though, because it's slow and uses lots of bandwidth. (Every time the
page is loaded, it's going to try and load lots of other pages, which have
to be pulled over the 'net.)

You can do (2), but not the way you describe. What you have to do here is
to set up a CGI script on the server to create the page, and then your
Javascript can tell the server to execute the script via XMLHTTPRequest
again.

Basically, I don't think Javascript is the right tool for solving your
problem. Unless there are other reasons why this *has* to be done in
Javascript, your best bet is to use a script running on the server written
in PHP or Perl or some such thing.

> Thanks ! i hope i post it correctly this time.

Yup, much improved. Ta.

- --
+- David Given --McQ-+ "I concluded from the beginning that this would be
| dg@xxxxxxxxxxx | the end; and I am right, for it is not half over
| (dg@xxxxxxxxxxxxx) | yet." --- Sir Boyle Roche
+- www.cowlark.com --+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFDXmeHf9E0noFvlzgRAsxYAJ98+WYJj0djDD/KD42JDNaYL0OuuACfWQZI
LZ+mR7xX9mO9JxKFON8mcyo=
=higU
-----END PGP SIGNATURE-----
.



Relevant Pages

  • Re: Stopping someone From Steeling Your Scripts
    ... prompted for your server login to view any page with the script linked to it ... from the _private folder. ... JavaScript is client-side, meaning that it is executed in the browser, ... page with a link to the script. ...
    (microsoft.public.frontpage.client)
  • Re: help getting value of cell and passing to PHP file
    ... locally run VBScript file using task scheduler on one of my servers. ... to click on any cell entry and have it send that value along with the server ... original script. ... think that might require some javascript as well though.. ...
    (comp.lang.javascript)
  • Re: ASP, Javascript Frontpage 2000
    ... The asp script you posted will work just fine - assuming your server ... like PHP to me) to grab the ip and javascript to display it. ...
    (microsoft.public.frontpage.client)
  • Re: History Replacement And New Location Combined
    ... will stop your script dead in its tracks. ... In his book "JavaScript - The Definitive Guide", ... clear the URL entry field in our form. ... Server Side Includes). ...
    (comp.lang.javascript)
  • Re: Refreshing parts of a web site
    ... AJAX script that checks the server every X minute and change the ... I found and modified a JavaScript that updates a div tag. ... Half lies are worth twice as much as whole lies. ...
    (alt.html)