Keep URLs simple by making them relative

Jake Howlett, 18 January 2001

Category: Quick Tips; Keywords: Relative Link URL

Do you use Computed Fields and/or Computed Text all over your forms in order to place URL references to things likes anchor links, stored images, linked files (CSS, JS) etc that are stored within the same database.

If so, then you may find it easier (the server definitley will) to use relative URLs.

Let's start by seeing how they would work in a standard HTML site.

Say you are in a document that is on a server and its path is:

"/jakeh/docs/homepage/hobbies1.html"

if you then wanted to link from this file to another file in the same directory ("homepage") you could use the following:

"<a href=hobbies2.html>...."

thus, cutting out the need to know, and to type, the whole directory structure.

Similarly you can use the dot dot syntax to get back through the directory. To get to a file in the preceeding directories you could simply type:

"<a href=../main.html>...." or "<a href=../../index.html>...."

This would launch the files stored at:

"/jakeh/docs/main.html" and "/jakeh/index.html", respectively

But that is for a file structure, what about in domino? I hear you cry. Well, you can use the same principles to greatly reduce the amount of code you need.

In domino we can treat its structure of views, forms and documents much like a conventional file structure.

For example, consider the following database path on a server:

"/dir1/dir2/db.nsf/view/doc?Open"

this follows much the same syntax as the above example file directory structure, treating the database and the view in the same way as directories and the document as being the file.

So .... don't worry I'm getting to the point .... if you want to a link from one document to another document in the same database you can create anchor links that are simply:

"<a href=DocumentID?Open>..." if in the same view.

"<a href=../view2/DocumentID?Open>..." if in another view.

If you are at view or form level in the database then you would create links like the following:

"<a href=viewname/DocumentID?Open>..."

Hopefully, you can see the benefits of the above and it will mean that 99% of your "DBName" type computed for display fields are now obsolete........

Notes:

Beware if you are writing HTML in the column of a view that will be captured by a DBLookup in order to create dynamic links at both the form/view level and the document level. The above method will not work !

Other Example:

It is not only useful for anchor links. If you have a view called "resources" that stores document with file attachments (images, JavaScript) etc then you can use the following:

"<img src=resources/DocName/$file/filename.gif>"

or if at the document level:

"<img src=../resources/DocName/$file/filename.gif>"

or in the HEAD tag of a document

"<script src=/DocName/$file/filename.js>"



Note: This tip appears in the January 2001 edition of Lotus Notes & Domino Advisor magazine. They had better send me one of those t-shirts, i always wanted one ;-)