benosullivan
04-12-2005, 05:09 PM
Dear all,
Need help!!:::
If you want your html doc to have an href to a file in the same folder is there a quicker way than simply typing in the full http://www.whatever.com/whatever/whatever.jpg?
have seen something like "../whatever.jpg" used - what are the rules for this? Can you code it so that it reads files in sister/brother directories as well as parent directories?
Many thanks, :eek:
Ben
mwinter
04-12-2005, 08:28 PM
If you want your html doc to have an href to a file in the same folder is there a quicker way than simply typing in the full [path]?Good &deity; yes! It would seem that you need a primer on URLs and path specifications. I'll give a complete description, but the simple answer is to just specify the filename. For example, you have a file x.html which has the complete URL,
http://www.example.com/a/b/x.html
and you want to refer to y.html in the same directory, you'd just include "y.html" in the href or src attribute. Alternatively, you could use a starting dot which refers to the current directory: "./y.html".
The rest of this post will be somewhat technical, but I'll try to provide enough examples to make things clear. If there's something that needs elaboration, please ask.
First of all, URLs are composed of several parts. Consider:
http://www.example.com/path/file.ext?name=value#fragment
This is as complete as a URL can be. It contains a lot of information, so I'll break it down. The various parts are the scheme (http), a hierarchical part (//www.example.com/path/file.ext), an optional query string (name=value), and an optional fragment (fragment). The hierarchical part can also be broken down into the authority (www.example.com) and the path (/path/file.ext).
When specifying a URL, you either specify an absolute URL, or a relative one. An absolute URL includes at the very least the scheme, the authority, and the path. That is,
http://www.example.com/
You should only need to use this form when specifying links to external sites, or if the scheme is different (for example, https or ftp). In all other situations, you should use the relative form.
Relative URLs only contain the path, and the optional query and fragment components. The path is resolved against the base URL. Generally, the URL of the current document. This is where things get rather complicated as a relative path can start in various ways: with a slash (/); a dot (.); two dots (..); or text.
A starting slash refers to the root directory. For example, the URL
/x.html
in a document at
http://www.example.com/a/b/y.html
refers to
http://www.example.com/x.html
A starting dot refers to the current directory. For example,
./x.html
at
http://www.example.com/a/b/y.html
refers to
http://www.example.com/a/b/x.html
Two starting dots refers to the parent directory. For example,
../x.html
at
http://www.example.com/a/b/y.html
refers to
http://www.example.com/a/x.html
Finally, there's the form where none of these punctuation characters start the URL. As I wrote at the very beginning, this is effectively the same as using a dot:
x.html
at
http://www.example.com/a/b/y.html
refers to
http://www.example.com/a/b/x.html
You can actually combine these forms to your heart's content. To refer to the parent's parent directory, you'd use two sets of double dots:
../../x.html
at
http://www.example.com/a/b/y.html
refers to
http://www.example.com/x.html
The combinations could even be pointless if you want:
../b/x.html
at
http://www.example.com/a/b/y.html
refers to
http://www.example.com/a/b/x.html
Exactly how you best construct relative URLs varies on the circumstances. If you want one URL to always refer to the same place, start with a slash.
There's one final thing to cover: same document references. You'll have probably seen them before with fragments that point to some place within the current document. For example,
#fragment
at
http://www.example.com/a/b/y.html
refers to
http://www.example.com/a/b/y.html#fragment
The same is true for query strings, too:
?name=value&i=1
at
http://www.example.com/a/b/y.html
refers to
http://www.example.com/a/b/y.html?name=value&i=1
Can you code it so that it reads files in sister/brother directories as well as parent directories?Only by going to the parent first, then back down the directory structure.
The official description of URLs is currently RFC 3986 (ftp://ftp.rfc-editor.org/in-notes/rfc3986.txt). It contains the complete generic syntax, a through description of all aspects of URLs, plus additional examples (near the end).
Hope that helps,
Mike
benosullivan
04-15-2005, 11:18 AM
Thanks so much for all of that - very helpful!
now looking for a way to overlay images on a page....
If I want images to overylay and use them as active links...
effectively - I have a large background picture which takes up most of the webpage and I want little images that overly that one that I can use as links.
what code do I need - any idea?
Ben
Powered by vBulletin® Version 4.2.2 Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.