HTML to generate "this" URL

D

David Blickstein

Is there a way in HTML to generate the URL of "this" page. I have a page
which moves around a lot and happens to be co-located with stuff that people
need to copy the URL of into an installation.

I'd rather have it just print the URL rather than awkward text that says
"take the URL of this page and..."

Thanks.

db
 
?

=?iso-8859-1?Q?Kim_Andr=E9_Aker=F8?=

David said:
Is there a way in HTML to generate the URL of "this" page. I have a
page which moves around a lot and happens to be co-located with stuff
that people need to copy the URL of into an installation.

I'd rather have it just print the URL rather than awkward text that
says "take the URL of this page and..."

In pure HTML? No. HTML is for document structure and layout references,
not for generating content. Although JavaScript might do it, it would
be an unreliable solution due to the fact that people can switch off
scripting languages in their browser, or be using a browser that
doesn't support any client-side scripting languages altogether.

The best solution would be to fetch the current URL by using a
server-side scripting language (such as Perl or PHP) or by using SSI
(Server Side Includes).

You can simply use the SERVER_NAME and REQUEST_URI environmental
variables to put together the URL of the current page.

List of common environmental variables and examples using SSI:
http://www.georgedillon.com/web/ssivar.shtml

Introduction to SSI and how to use it:
http://www.georgedillon.com/web/ssi.shtml
 
M

Mitja Trampus

David said:
Is there a way in HTML to generate the URL of "this" page. I have a page
which moves around a lot and happens to be co-located with stuff that people
need to copy the URL of into an installation.

I'd rather have it just print the URL rather than awkward text that says
"take the URL of this page and..."

Just HTML, no. With javascript, yes, but make sure you don't
make javascript a neccessity for understanding the
instructions because it can be disabled.

Do something like:
<body onload="updateContentsOfLocalUrlSpanWithCurrentUrl()">
<p>
Take the URL of this page (<span id="localUrl">copy-paste
from address bar</span>) and do foo with it.
</p>

The JS function you need is simple, an one-liner:
document.getElementById("localUrl").innerHTML = location.href
Note that this piece of JS is far from perfect (regarding
cross-browser issues), but I'm not exactly an expert on that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top