![]() |
|
|
| Subject:
Properties of a URL
Category: Computers > Programming Asked by: omoolorun-ga List Price: $20.00 |
Posted:
15 Oct 2005 19:03 PDT
Expires: 14 Nov 2005 18:03 PST Question ID: 580772 |
I wrote a slide show javascript and also downloaded similar scripts
from the web. Created HTML files using AceHTML PRo software for all
these slide show files. These files are on my C drive. I created a
file for all my pictures on my D drive with extension jpg.
On testing each slide show HTML code file in IE, Maxthon and Opera,
the first picture shows and not the rest of the remaining pictures.
Whenever I click next, for more pictures, I get a blank page with a
little red x where the
picture was to have been. Right clicking the red x and going to
Properties revealled this statement at the URL "file:///d:%02.jpg"
This is my code: "var picture = new Array("d:\1.jpg", "d:\2.jpg", "d:\3.jpg")
Can you explain File:///d:%02.jpg? | |
| |
|
|
| Subject:
Re: Properties of a URL
Answered By: leapinglizard-ga on 16 Oct 2005 23:02 PDT Rated: ![]() |
Dear omoolorun,
The reason your page correctly displays the first picture is that its
location is specified by the HTML code as src="d:\1.jpg", which
translates directly into the string "d:\1.jpg".
But when you click on the "Next Picture" link and the JavaScript gets
called, the next element of the array is "d:\2.jpg", which gets
translated by the JavaScript interpreter into the invalid location
"d:%02.jpg". This is because the backslash character, "\", has a
special meaning in JavaScript that causes it to render special
characters. If you intend a JavaScript string to include the backslash
character itself, you must write it twice in a row: "\\". Thus, when
you are using a JavaScript string to specify the file location
d:\2.jpg, you should write it as "d:\\2.jpg".
You will find that the HTML source code below achieves the intended
effect. If you wish to preserve your own prefatory tags, you can just
cut the script out of your current file and paste in my own as a
substitute.
If you have any trouble carrying out this substitution, please advise
me through a Clarification Request so that I can make sure everything
is working at your end before you rate my answer.
Regards,
leapinglizard
<html>
<head>
<script language="JavaScript">
//<!--
var picture = new Array("d:\\1.jpg", "d:\\2.jpg", "d:\\3.jpg",
"d:\\4.jpg", "d:\\5.jpg", "d:\\6.jpg",
"d:\\7.jpg", "d:\\8.jpg");
var picNumber = 1;
var numberofPics = picture.length;
function nextPicture() {
if (picNumber < numberofPics){
picNumber++;
}
else {
picNumber = 1;
}
//alert(picture[picNumber-1]);
document.myPicture.src = picture[picNumber-1];
}
//-->
</script>
</head>
<body>
<center>
<img src="d:\1.jpg" name="myPicture" width=400, height=400>
<p>
<a href="JavaScript:nextPicture()">Next Picture</a>
</p>
</center>
</body>
</html> |
omoolorun-ga
rated this answer:
Great job and thanks! |
|
| Subject:
Re: Properties of a URL
From: wildwestwind-ga on 15 Oct 2005 19:44 PDT |
In JavaScript the character \ embedded in a string is a special
"escape" character which modifies the following character rather than
representing \ itself. In order to create \ as output you need to
double it, as in "\\".
So you might want to try
var picture = new Array("d:\\1.jpg", "d:\\2.jpg", "d:\\3.jpg")
or
var picture = new Array("d:/1.jpg", "d:/2.jpg", "d:/3.jpg") |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
| Search Google Answers for |
| Google Home - Answers FAQ - Terms of Service - Privacy Policy |