PDA

View Full Version : document.referrer help


shashgo
09-21-2002, 02:22 PM
Hi,
1) if i open a new page using javascript by saying

<script language="javascript">
newWin=window.open("","");
newWin.document.write("<html><head><title></title></head>");
newWin.document.write("<body><script language='javascript'>");
newWin.document.write("This page referred to by: "+document.referer);
newWin.document.write(</script></body></html>);
</script>

will the newly opened page dispay the referring URL correctly?

2) Also if I link from one page to another and have the second page say
document.write("Referred to by "+document.referer);
will it work?

For some reason I cant get them to work. What am i doing wrong?

Dynasty
09-21-2002, 03:28 PM
<script language="javascript">
newWin=window.open("","");
newWin.document.write("<html><head><title></title></head>");
newWin.document.write("<body><script language='javascript'>");
newWin.document.write("This page referred to by: "+document.referer);
</script>

That appears to work for the first one.

shashgo
09-21-2002, 03:51 PM
To Dbindel,

I mistyped in the post, I do use document.referrer but I cant get it to work. I dont get and undefined either, just a blank. I'm talking about linking to another window with the tag
<a href="second.htm">

and having the file second.htm have the script
document.write("Referred by: "+document.referrer);

It still doesnt work
Why?

I have MSIE6

Josh
09-21-2002, 08:09 PM
I've find out the problem.It works,but it's vbscript. HTH:) <script language="vbscript">
set newWin=window.open("","")
newWin.document.write("<html><head><title></title></head>")
newWin.document.write("<body><script language=javascript>")
newWin.document.write("document.write(""This page referred to by: ""+document.referrer);")
newWin.document.write("</scr" + "ipt>")
</script>

Josh
09-21-2002, 09:02 PM
Yeah,I know vbscript could only run at MSIE. but I have a problem is that I don't know how to insert " between two "s in javascript.And this is the main problem of the original code.

Josh
09-21-2002, 09:24 PM
thanks dbindel.Here's the javascript code:
<script language="javascript">
newWin=window.open("","");
newWin.document.write("<html><head><title></title></head>");
newWin.document.write("<body><script language=javascript>");
newWin.document.write("document.write(\"This page referred to by: \"+document.referrer);");
newWin.document.write("</scr" + "ipt>");
</script>

Josh
09-22-2002, 03:18 AM
Thank you.
I've posted Admin before,just waiting for his reply;)

shashgo
09-22-2002, 07:08 AM
Josh,
I typed the code exactly the way you have it, but all I get is
");

I cant get it to work. Not only that , it doesnt opn a new window now. Whats wrong?

And why do you have the </script> written as "</scr"+"ipt>"?


Dbindel,

I tried the code with the escaped "(\")". didnt work. i got a ");. then I tried replacing the "\" with a '. Same result. What gives? and I still dont get a newwindow.

And the status line reads, Done, but with errors on page

Josh
09-22-2002, 07:21 AM
Originally posted by shashgo
And why do you have the </script> written as "</scr"+"ipt>"?

so that's the problem,if you write "</script>" then the browser will thought it was the end of the script,and it'll display error.
HTH.:)

shashgo
09-22-2002, 07:42 AM
Josh,

Yes, I tried it with the "</scr"+"ipt>", and it does open a new wwindow. But the document.referrer part still gives a blank.
So what I get is
This document referred to by:

What gives?

shashgo
09-22-2002, 08:18 AM
dbindel,

Cool, it works with the parent.location.
But then when can we use document.referrer, and does it work?

What Im trying to do is cread a website that has all the links followed to get to a certain page listed on the page as a trail, similar to what yahoo has on its pages
(Ex: Education->Schools->K12-Teachers)

Also the other thing is say if I open another window by linking to it either through

window.open("SomeURL.htm");
or
<a href="SomeURL.htm>SomeURL</a>

then what do I add on the SomeURL.htm page to get the referring page location, document.referrer or parent.location?

By the way, what does HTH stand for?

shashgo
09-22-2002, 09:32 AM
dbindel,

Youre right about the parent.location only working for popups. I cannot get the document.referrer to work for links though.

This is what I have as the first.htm

<html><head><title></title></head><body>
<a href="second.htm">Link</a>
</body></html>

and this is second.htm

<html><head><title></title></head><body>
<script language="javascript">
document.write("This page referred to by "+document.referrer);
</script>
</body></html>

Doesnt work. How come?

Josh
09-23-2002, 02:03 AM
If it doen't works why use it?
just use document.location

yuvarajs
03-10-2005, 01:51 PM
folks

I am having kinda a similar issue. if you folks could help me out, that would be great.

All I need to do is, I have to reload the parent document once the pop-up is closed. I pop open a window through clicking a link in the parent page. Does some processing there. Submits the form. I am closing the popup on submission. The changes done there should be reflected in the parent page. This is currently done by Manual reloading of the page. I need it to be done automatically at the closure of the pop up window.

Help please.

gscragg
04-19-2005, 02:55 PM
I had the same problem but I managed to fix it.

For popup windows you can see what the refferer was with:
window.opener.location;

and to refresh the parent window use:
window.opener.location.refresh();

or
window.opener.location.href = window.opener.location.href (this is a guess)