HTML5, CSS3, and JavaScript Fourth Edition

(Ben Green) #1

CHAPTER 6. USING EXTERNAL RESOURCES 68


6.11 We Can Change Our Base


Your natural base for calculating relative URLs is the complete URL of your
current webpage.


HTML allows you to specify a different base than your natural base. You
can include one base declaration in the head of your webpage.



That would mean “please act as though this webpage were actually located
at http://example.org/abc/ even though you may have come to it by using
a different URL. This can be handy if the webpage has one or more aliases.


All the relative addresses in the webpage would use the declared base instead
of the natural base.


Exam Question 107(p.342): If our base URL is http://a.com/b/c/ and
our stated URL is ../d/e/ what is our final URL?
Required Answer:http://a.com/b/d/e/


Exam Question 108(p.342): If our base URL is http://a.com/b/c/ and
our stated URL is ./d/e/ what is our final URL?
Required Answer:http://a.com/b/c/d/e/


Exam Question 109(p.342): If our base URL is http://a.com/b/c/ and
our stated URL is /d/e/ what is our final URL?
Required Answer:http://a.com/d/e/


Exam Question 110(p.343): If our base URL is http://a.com/b/c/ and
our stated URL is d/e/ what is our final URL?
Required Answer:http://a.com/b/c/d/e/


If the stated URL starts with slash, we throw away all the path from the
base URL and just add the stated URL.


For any other relative address, we combine the base URL and the stated
URL. Then, every time we find ../ we delete it and the previous chunk of
path. Every time we find ./ we just delete it.


6.12 Connecting With External Resources


A webpage is seldom complete in itself. Most often it refers to images and
other webpages. Also it refers to external style sheets.

Free download pdf