Re: Checking if a file exist
- From: dg@xxxxxxxxxxxxxxx (David Given)
- Date: Tue, 25 Oct 2005 17:09:50 GMT
-----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-----
.
- Follow-Ups:
- Re: Checking if a file exist
- From: batels
- Re: Checking if a file exist
- References:
- Checking if a file exist
- From: batels
- Re: Checking if a file exist
- From: David Dorward
- Re: Checking if a file exist
- From: batels
- Re: Checking if a file exist
- From: Evertjan.
- Re: Checking if a file exist
- From: batels
- Checking if a file exist
- Prev by Date: Re: Unzip Zip files with javascript
- Next by Date: Re: A tag: href vs. onClick
- Previous by thread: Re: Checking if a file exist
- Next by thread: Re: Checking if a file exist
- Index(es):
Relevant Pages
|