PDA

View Full Version : document.referrer and image loading


shashgo
09-23-2002, 08:09 PM
I hav two questions

1) I need to know how I can use javascript to refer to pages that are linked to. I tried to display document.referrer on the new page but it doesnt return anything

so if I have a page (say one.htm) with a link
<a href="two.htm">two</a>

and in two.htm I write
<script language="javascript">
document.write("Referred to by: "+document.referrer);
</script>

then shouldnt h output be Referred to by: one.htm
I only get Referred to by:

Why is it not working? What am I doing wrong?

-----------------
2) I want to design a web page where I use javascript to load all the images on my hard drive without me having to specify each individual name. The images have filenames that are 1.jpg, 3.jpg, 4.jpg, 7.jpg, 10.jpg, 15.jpg, 30.jpg,... no order.

How can I accomplish this?

Josh
09-24-2002, 04:32 AM
I've just figured out 1),try this:first.html:
<a href="second.html">blah</a>
<script>
document.cookie=document.location;
</script>
second.html:
<script>
document.write(document.cookie);
</script>HTH

shashgo
09-24-2002, 09:30 AM
Hi Josh,

Your code works. But it uses cookies. If nothing else, Ill probably do what you said. But then does document.referrer ever work, an if so how is it used?

Josh
09-24-2002, 03:38 PM
I think it could only use cookies.
Document.referrer never works,I duno why.

David.Prout
09-26-2002, 07:19 AM
document.referer does not work if you are only browsing the files on a local drive, eg C: drive. It does work if you are browsing the files hosted on a web site, eg http://TestSite.com/testsite/test.html.

Hope that helps.

David.Prout
09-26-2002, 07:20 AM
Of course http://TestSite.com/testsite/test.html does not exist, it's just an example url for when browing a file hosted on a web site/server.

:)

Josh
09-26-2002, 03:32 PM
But I've upload it to my sever,still doesnt't work

EnwTheGood
09-26-2002, 07:15 PM
1) document.referrer should work. Check your spelling, and make sure that referrer logging is on in your browser and that you're not using IE3.02 (which has document.referrer disabled).

2) There are two limitations to that picture-loading thing. Firstly, though JS can read files, it doens't have the authority to search for them on the server. Also, even if you were to find the filenames, your only option would be to stream them into the Javascript code, so you'd need to output each one to a temporary image file, reload the page, and then display the page with the temp images. I suggest just using a server-side language, if possible.

Also, I've read things saying that it could be done using Java code embedded in JavaScript, but I don't remember the link right now.

Josh
09-27-2002, 02:10 AM
Check this link,it really doesn't work.
http://home.kimo.com.tw/asdfghjkl953/test.html

David.Prout
09-27-2002, 02:13 AM
I went to that link, from the link you posted on this forum, and document.referrer worked. The forum page I came from was show in the browser (IE6 with SP1).

Josh
09-27-2002, 02:42 AM
Now I know how to use it,thanks.
2shashgo:this is another code:first.html:
<a href="second.html">blah</a>second.html:
<script language=javascript>
document.write(document.referrer);
</script>