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

?


From: Nospam on
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" <nospam(a)home.com> wrote in message
news:ZjOSg.42411$8V4.23541(a)newsfe5-win.ntli.net...
> does anyone know if there is anything wrong with this code? <SCRIPT
> LANGUAGE="JavaScript">document.referrer.indexOf("http://www.example.com")
> != -1){ document.write("http://www.example.com/image1.jpg")} </SCRIPT>
>
> ?
>
>


From: Evertjan. on
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)
From: Randy Webb on
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/
From: web.dev on

Nospam wrote:
> does anyone know if there is anything wrong with this code? <SCRIPT
> LANGUAGE="JavaScript">document.referrer.indexOf("http://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.