SitePoint Sponsor |
|
User Tag List
Results 1 to 12 of 12
-
Jan 6, 2003, 12:17 #1
- Join Date
- Sep 2002
- Location
- Bournemouth, South UK
- Posts
- 1,551
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
check file exists before linking....
Is there a way of checking a file exists before linking to it?
I sell didjeridoos and handdrums.
I was hoping to create small html program for each drum, somthing like this....
<script>
thisdrum=new Image()
thisdrum src=drum001.gif
price=100
rim=12
height=24
</script>
<script src=createpage.js>
</script>
and saved as drum000 to drum999
Now I need a function included in the creatpage.js, that checks if a file exists,(eg drum000.html) if it does, go there, if it doesn't, try drum001.html
any suggestions on how I could go about it?LiveScript: Putting the "Live" Back into JavaScript
if live output_as_javascript else output_as_html end if
-
Jan 6, 2003, 14:23 #2
- Join Date
- Aug 2002
- Location
- Wellington, New Zealand
- Posts
- 861
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Firstly why do you actually want to do that? What is the end result you are hoping to accomplish? as there might be a better solution available.
Its quite a tricky thing to do at the browser. Be much easier to use ASP or PHP and construct your page according to what files exist at the server.
The only way I can think to see if the file exists from the browser would be to attempt to load it, and then when it is loaded check what really got loaded and if a 404error.html got loaded then to automatically reload the next file. That would be fairly complex if indeed actually possible.If you aren't living life on the edge
- you're taking up too much space
Creative Dreaming Ltd / Ask The Local / Amanzi Travel
-
Jan 6, 2003, 15:20 #3
- Join Date
- Sep 2002
- Location
- Bournemouth, South UK
- Posts
- 1,551
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
new windows maybe?
I could open the new file in a new window above the current window, the opener checking if the new window has loaded properly, if it has, close the opener, if it hasn't, load next file in the new window. I suppose something like that would work??
LiveScript: Putting the "Live" Back into JavaScript
if live output_as_javascript else output_as_html end if
-
Jan 6, 2003, 15:39 #4
- Join Date
- Jul 2002
- Location
- Dallas, TX
- Posts
- 2,900
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well, I suppose you COULD have some scripting in the opened page 'talk' to the opener page to let it know that it's there, and if that communication doesn't take place after a set number of seconds the opener page will proceed with the next file. However, that would be very anal at best. As dale said, this would be much better done in PHP or the like.
-
Jan 6, 2003, 17:40 #5
- Join Date
- Sep 2002
- Location
- Bournemouth, South UK
- Posts
- 1,551
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
my server only supports Perl
Trying to get my first perl script to work right now!
It's not going as well as the learning of javascript,
but once i've got my first script to work I hope I'll be OK.
I was thinking of the above method after.....a lot of clicking!!!!
Thanks again.LiveScript: Putting the "Live" Back into JavaScript
if live output_as_javascript else output_as_html end if
-
Jan 6, 2003, 18:12 #6
- Join Date
- Sep 2002
- Location
- Bournemouth, South UK
- Posts
- 1,551
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Check for drum pic first????
Just found this....
<script language="JavaScript"><!-
function testImage(URL) {
var tester=new Image();
tester.onLoad=isGood;
tester.onError=isBad;
tester.src=URL;
}
function isGood() {
alert('That image exists!');
}
function isBad() {
alert('That image does no exist!');
}
//--></script>
I could check that the drum picture exists first, then bring in the .html file which has the description, calling the .js to put the page together.
To put a new drum in the website, I call the pic drum2.jpg, and put a drum2.html file with it(which calls showdrums.js). To take the drum out, I delete the .jpg file (using ftp for now)
Maybe I could get round it this wayLiveScript: Putting the "Live" Back into JavaScript
if live output_as_javascript else output_as_html end if
-
Jan 7, 2003, 13:35 #7
- Join Date
- Sep 2002
- Location
- Bournemouth, South UK
- Posts
- 1,551
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
can't get it to work.....can u help?
I have been trying to incorporate the onError with the img preload;
for(i=drum;i<999;i++)
nextdrumimage=new Image;
nextdrumimage.src="drums/"+i+".gif"
but I am having trouble.
Once I have it, then I only need this to go with each pic;
<html>
<script>
drum=0
price=250
height=80
diameter=40
description="a loud wooden drum"
</script>
<script src="../putogether.js" language="javascript" type="text/javascript">
</script>
I dont need it to be picked up by search engines, as the page will be linked from a HTML document that has the necessary keywords
This would make it really easy to add new items to the website, with each small HTML calling the .js which looks for the next .gif, resulting in showing the next .html, which calls the .js which looks for the next .gif.......and so on and so on utill it reaches 999, then either goes back to 0 or displays "NoMoreImages.gif"
But I need the onError to work with the img preload.
I AM going to choose this method.(If possible)
I hope you can help me apply it!!! thanks in advance.LiveScript: Putting the "Live" Back into JavaScript
if live output_as_javascript else output_as_html end if
-
Jan 7, 2003, 17:17 #8
- Join Date
- Sep 2002
- Location
- Bournemouth, South UK
- Posts
- 1,551
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
works perfectly!!!!!
function findprev() {
prevdrum--
document.pdrum.src=prevdrum+".gif"}
function findnext() {
nextdrum++
document.ndrum.src=nextdrum+".gif"}
document.write(
'<img src='+prevdrum+'.gif name="pdrum" width=30 onError="findprev()">',
'<img src='+thisdrum+'.gif>',
'<img src='+nextdrum+'.gif name="ndrum" width=30 onError="findnext()">')
I just name the pic files; 0.gif,1.gif,2.gif,65.gif,
with the above html file, named; 0.html,1.html,2.html,65.html
If I click on 0.html, it keeps looking for an image name a number less than 0,
Clicking on 1.html, shows 0.gif,1.gif,2.gif
clicking on 2.html, shows 1.gif,2.gif,65.gif (it keeps looking until its found it)
The variable nextdrum(65) will then make up the next file to go to.........65.html
It works!! now I only have to save a image, and a small html file with each object I want to introduce!!
If you think its rubbish, let me know of another way.LiveScript: Putting the "Live" Back into JavaScript
if live output_as_javascript else output_as_html end if
-
Jan 7, 2003, 19:05 #9
- Join Date
- Sep 2002
- Location
- Bournemouth, South UK
- Posts
- 1,551
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Stack overflow at line:0 error
Now I've got this far,
this is saved in a file called 'drums' as 4.html, along with others of a similar name and content
Code:<html> <script> drum=4 price=125 height=40 diameter=20 description="quiet wooden drum" </script> <script src="../putogether.js" language="javascript" type="text/javascript"> </script>
Code:thisdrum=drum prevdrum=drum-1 nextdrum=drum+1 function findprev() { prevdrum-- document.pdrum.src=prevdrum+".gif"} function findnext() { nextdrum++ document.ndrum.src=nextdrum+".gif"} document.write( '<img src='+prevdrum+'.gif name="pdrum" width=30 onError="findprev()" onclick=alert(prevdrum)>', '<img src='+thisdrum+'.gif>', '<img src='+nextdrum+'.gif name="ndrum" width=30 onError="findnext()" onclick=alert(nextdrum)>', 'diameter='+diameter, 'height='+height, 'price='+price)
LiveScript: Putting the "Live" Back into JavaScript
if live output_as_javascript else output_as_html end if
-
Jan 7, 2003, 19:55 #10
- Join Date
- Sep 2002
- Location
- Bournemouth, South UK
- Posts
- 1,551
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Only allows a count of 8.....
I can check up to 8 pictures from the original starting pic, but after that it comes up with the Stack Overflow Error......
LiveScript: Putting the "Live" Back into JavaScript
if live output_as_javascript else output_as_html end if
-
Jan 10, 2003, 05:23 #11
- Join Date
- Sep 2002
- Location
- Bournemouth, South UK
- Posts
- 1,551
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Just In Case......
Just in case anyone liked the look of this program, there's no Stack error online!!
so if you have stock to show(or anyhting for that matter)
just name the pic a number, (could be a page number pic)
and look for the pic using a loop, then bring in corresponding .html.
Good if you just want to add things to your site without changing existing program.LiveScript: Putting the "Live" Back into JavaScript
if live output_as_javascript else output_as_html end if
-
Jan 10, 2003, 07:11 #12
- Join Date
- Sep 2002
- Location
- Bournemouth, South UK
- Posts
- 1,551
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Another Thought.......
Another thought, which nobody pointed out, is that if I could check whether a .html file existed and then link to it, I could set up a program to look for peoples hidden .html or other documents, which are in their ftp folder but they do not wish to share.
It would be another security risk!!!LiveScript: Putting the "Live" Back into JavaScript
if live output_as_javascript else output_as_html end if
Bookmarks