HTML to generate "this" URL

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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..."



Re: HTML to generate "this" URL

David Blickstein wrote:

Quoted text here. Click to load it

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:

Introduction to SSI and how to use it:

Kim André Akerø
(remove NOSPAM to contact me directly)

Re: HTML to generate "this" URL

David Blickstein wrote:
Quoted text here. Click to load it

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()">
Take the URL of this page (<span id="localUrl">copy-paste
from address bar</span>) and do foo with it.

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.

Site Timeline