Forum Moderators: open

Message Too Old, No Replies

How to force to show FULL URL?

javascript - full url

         

arruda00

5:55 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



I want that in one or each page of one site, it shows in the text of the page the FULL URL of it

(example:
Full URL:
htpp://www.sitename.com/articles/article1.html)

Can this may be done by javascript?
I tried and I can't do it.
It is to be similar as when the page was created, etc.
(proprieties of page, but with the full address as it appears on the browser).

Can anyone help me?

Thank You.
Arruda, Joseph

arruda00

6:02 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



In addition:

The code that I wrote was the following:

<SCRIPT LANGUAGE="JavaScript">

<!--
{
document.write(location.href);
}
// -->
</SCRIPT>

---
What is wrong?

Bernard Marx

7:53 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Getting rid of those curly brackets should do it, I reckon.

arruda00

8:43 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



Thanks, Bernard.
It works!

Now, one more question (if you can help me).

There's any way to record the «result» that is showed in the proper page?

I explain. With the script, the page appears like this:
«The url for quotation is www.name.com/file.html»

But, if anyone save the page to a file in the hard disk, it copies the script command and when the person run the file, it will appear «The url for quotation is file C:/example/file.html». There are any way that in the file saved it appear the real URL from where the page was saved (www.name.com/file.html)?

Thanks
Arruda.

klogger

9:56 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



JavaScript is a client side language and so can only read local information which is why you get the C:\ part. I think the only way around it is to hard code each page into the document so you get:

document.write("www.mysite.com/page.html");

Then again if you are doing that you may as well just write the page name using HTML :)

Bernard Marx

10:15 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Klogger's right.

idea: In IE, there is a feature called "persistence". If used, I think form input fields keep their values when the page is saved (using File > Save as). The URL could be put in a hidden field. Persistence isn't in my trickbag.

arruda00

10:44 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



I found at [webreference.com...] information about the result of persistance in userdata.

But it is to much for my acknowledge about javascript. Can it be possible to adapt that option in saving the results of a javascript action?

Thank you.
Arruda.

Bernard Marx

11:00 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



(Didn't see you post when I posted this, arruda. Having a look now). Meanwhile...

Silly idea for you.
< amended since first posted.
I have just thought of a better idea. I'll leave this here because it meets sillyness requirements. >

When a document is saved in IE using "Web Page, complete" (not "Web Page, HTML only"), then you will find this in the source code (for eg):


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0046)http://www.webmasterworld.com/forum91/2291.htm -->

We can grab that string in the comment, and mess with it until we have the URL in a variable:

[pre]
<script>

var URL = getCommentURL()
// If URL returned,
// write it into a link, for instance
if(URL)
document.write(
"&lt;&lt; <a href=\"" +URL+ "\">" +URL+ "</a> &gt;&gt;"
)
//
function getCommentURL()
{
// get the first comment node's text
// In IE, this is all: from <!-- to -->
var comm = document.getElementsByTagName("!")[0]
// if no comments, stop
if(!comm) return null
var text = comm.text
//grab the bit from where the url starts, to the end
var URL = text.substring(text.indexOf("http"),text.lastIndexOf(" "))
// return the URL
return URL
}
</script>

[/pre]

This function can be safely put, or linked into the <head> section, since the comment is always at the top, below the <DOCTYPE>,
so it has always loaded before the script is executed.