473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

document referrer

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
5 10985
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
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
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

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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Daniel | last post by:
Hi, All! I have a problem - I manage two websites, with two different style sheets (one for each site), but they both share hte same public message boards and I want to change the CSS used by...
9
by: goks | last post by:
I'm using document.referrer method for tracking visits on my site. But it seems that, when someone finds my site with google, this method returns only: "google.com/search?q=xxxxx" (good) or...
1
by: kuok benny | last post by:
Hi, I am trying to use the document.referrer to get the referrer of my home page. Occationally, I get the value of 'blockedReferrer'. Actually how this happen, how the client blocked the...
9
by: Frances Del Rio | last post by:
if I put alert(document.referrer) in code of a file that was linked from another it returns blank... pls, need to get document.referrer, don't why it's not working... read up on oreilly, don't...
2
by: Goober | last post by:
I have to determine the document.referrer of the individual coming to my site. I want to send everyone not coming from one of those sites to an alternate location (The names below are just used as...
2
by: X l e c t r i c | last post by:
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...
1
by: Mike Dee | last post by:
Hi All - I'm having a strange problem I'm wondering if anyone can shed some light on. When I use ASP or ASP.NET code to get the referrer information from the server side, it comes back as null. ...
1
by: gocre8 | last post by:
hope someone can advise! . . . i'm using this code... <SCRIPT LANGUAGE="JavaScript"> document.write("<INPUT type=hidden NAME=referrer VALUE=" + 'document.referrer' + ">"); </SCRIPT> to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.