document.referrer value to text input

  • Thread starter X l e c t r i c
  • Start date
X

X l e c t r i c

Hi,

I'm trying to put the last URL visited to a text input using
history.previous for WebTV (because I can't get document.referrer to
work with WebTV) and document.referrer for PC. This is for my Web
Resources page. Where if I go straight to it from an image that I want
to edit with an online imaging tool, or if I go straight to it from a
page that I want to validate, I can put the URL to the text input of the
portal I want to use.

I'm getting varied results with the PC (IE6). When I click on the page
that has this in my file manager it works. But when I access the page
from my favorites it doesn't work.

Here's a link to an example/test page:

http://www.xlectric.com/resources/lasttest.html

Below is the code for the forms and JavaScript that I'm using.

Thanks for any help.

Later, Art.

<form action="javascript:void()" onsubmit="return false;">
Last URL
<br />
<input type="text" id="last" size="50" />
</form>
<form id="last2" action="javascript:void()" onsubmit="return false;">
<p>
<a href="javascript:showLast('last2');">Show Last URL</a>
&nbsp;&nbsp;&nbsp;<a
href="javascript:document.getElementById('last2').reset();">Reset</a>
<br />
<input type="text" size="50" />
</p>
</form>

<script type="text/javascript">
<!-- Xlectric Script
var s_last;
if (navigator.appName.indexOf("WebTV") != -1)
{
s_last = history.previous;
}
else
{
s_last = document.referrer;
}
document.getElementById("last").value = s_last;
function showLast(f_last)
{
document.getElementById(f_last).elements[0].value = s_last;
}
//-->
</script>
 
B

Bart Van der Donck

X said:
I'm trying to put the last URL visited to a text input
using history.previous for WebTV (because I can't get
document.referrer to work with WebTV) and
document.referrer for PC. This is for my Web Resources
page. Where if I go straight to it from an image that I
want to edit with an online imaging tool, or if I go
straight to it from a page that I want to validate, I
can put the URL to the text input of the portal I want
to use.

I'm getting varied results with the PC (IE6). When I
click on the page that has this in my file manager it
works. But when I access the page from my favorites it
doesn't work.

The history object is suspicious about reading out previous url's
because of security and privacy reasons. Things like document.referrer
and history.previous have only limited support.

The reason why it still works in your demo, is maybe because both
scripts are on the same domain.

It is a better idea to handle this kind of functionality at the server
side. See php, cgi, ssi...
 

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

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,161
Latest member
GertrudeMa
Top