By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,570 Members | 1,724 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,570 IT Pros & Developers. It's quick & easy.

document referrer

P: n/a
does anyone know if there is anything wrong with this code? <SCRIPT
LANGUAGE="JavaScript">document.referrer.indexOf("h ttp://www.example.com")
!= -1){ document.write("http://www.example.com/image1.jpg")} </SCRIPT>

?
Sep 28 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
or how to property set document.referrer, would something like this work:

<SCRIPT LANGUAGE="JavaScript">
{
document.referrer == 'http://www.example.com;
document.write('<img src=http://www.example.com/image1.jpg width="60"
height="60">');

}
</SCRIPT>
"Nospam" <no****@home.comwrote in message
news:Zj*******************@newsfe5-win.ntli.net...
does anyone know if there is anything wrong with this code? <SCRIPT
LANGUAGE="JavaScript">document.referrer.indexOf("h ttp://www.example.com")
!= -1){ document.write("http://www.example.com/image1.jpg")} </SCRIPT>

?


Sep 28 '06 #2

P: n/a
Nospam wrote on 28 Sep 2006 in comp.lang.javascript:
or how to property set document.referrer, would something like this
work:
<SCRIPT LANGUAGE="JavaScript">
use:

<script type='text/javascript'>
{
no need for the {
document.referrer == 'http://www.example.com;
You forgot the closing apostrophe of the string:

document.referrer == 'http://www.example.com';

Are you sure document.referrer would not return:
'http://www.example.com/'
or
'http://www.example.com/index.html'
etc?

Or do you want to test true for any referrer from that domain?

The double '==' compares the two strings, but you do not use the result.

Do you mean:

if (document.referrer == 'http://www.example.com')
document.write('...

??

document.write('<img src=http://www.example.com/image1.jpg width="60"
height="60">');
I would enclose the URL string in quotes
scr="http://www.example.com/image1.jpg"
width="60"
height="60"
Use css styles:

style='width:60px;height:60px'

>
}
no need for that }
</SCRIPT>
===============

I would suggest the following:

<script type='text/javascript'>

var url = 'http://www.example.com';
var s = "<img src='"+url+"/image1.jpg'";
s += " style='width:60px;height:60px'>";

if (document.referrer.substr(0,url.length) == url)
document.write(s);

</script>

not tested

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 28 '06 #3

P: n/a
Nospam said the following on 9/28/2006 8:46 AM:
or how to property set document.referrer, would something like this work:
Did you test it? You didn't or you wouldn't be asking that question.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 28 '06 #4

P: n/a

Nospam wrote:
does anyone know if there is anything wrong with this code? <SCRIPT
LANGUAGE="JavaScript">document.referrer.indexOf("h ttp://www.example.com")
!= -1){ document.write("http://www.example.com/image1.jpg")} </SCRIPT>
The language attribute is deprecated, use type instead:

<script type = "text/javascript">
>From what I gather, you're saying if I didn't come from the example
site, then you're gonna take and use their content. I would say that's
the only thing wrong with your code. And it's not foolproof, meaning I
could come from different site, and there would be no way that you
could cover all the cases. I don't even have to come from a site. I
can just launch an empty window, and navigate to your site. In which
case, document.referrer would be empty.

Sep 28 '06 #5

P: n/a

Nospam wrote:
or how to property set document.referrer, would something like this work:
document.referrer == 'http://www.example.com;
1. The referrer property is a read-only value.
2. You're doing an equality comparison.
3. Even if referrer wasn't read-only, and you were doing an assignment,
then you have an unterminated string.

Sep 28 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.