990918-3

The directory main has two subdirectories images and text. The images directory contains gif files, the text directory contains html documents using these gif files. How can such an html document refer to one of the images?

Your solution should work independently of the position of the cirectory main, and not require rewriting of the html code if main with its subdirectories is moved.

Answer

<IMG SRC="../images/image1.gif">

Since the document should not be changed if the directory main is moved, no absolute URLs can be used, either in an IMG or in a BASE statement. The relative URL "../images/image1.gif" starts with the URL of the text document, "http://somewhere/main/text/text1.html". ".." goes up one directory level, and thus gives "http://somewhere/main/". "images/" goes down one directory level again to the images directory.

Note: If “main” is the root directory of the web site, directly following “http://”, then the following construct can also be used:

<IMG SRC="/images/image1.gif">

List of exam questions