"Orphan" pages on a website

  • Thread starter Thread starter Trevor L.
  • Start date Start date
T

Trevor L.

Since changing my site to non-framed, I end up with a lot of pages which can
be opened on their own and which have no apparent connection to my home
page. (Previously, if a frame was opened directly, there was a redirect to
the frameset.)

Is there a way to detect whether a page has been opened from another page in
the same site?

If there were, then I could put up a message saying "The Home Page of this
site is ...." together with a button to click to get there.

I thought of searching the History array and if there existed an entry for
http://tandcl.homemail.com.au/index.html, then I coudl assume that the site
had been entered from the home page.

But I have tried alert(history(0)) and alert(history[0]) - neither works.
One gives undefined the other gives nothing (in reverse order, I think).

In the meantime, I have put a Home button on most pages with
onclick="location.href='index.html'". On other pages, I have just put a
Close button.
 
Trevor L. said the following on 3/7/2006 1:22 AM:
Since changing my site to non-framed, I end up with a lot of pages which can
be opened on their own and which have no apparent connection to my home
page. (Previously, if a frame was opened directly, there was a redirect to
the frameset.)

Is there a way to detect whether a page has been opened from another page in
the same site?
alert(document.referrer)

alert(document.referrer.indexOf('yourSite'))

If there were, then I could put up a message saying "The Home Page of this
site is ...." together with a button to click to get there.

I thought of searching the History array and if there existed an entry for
http://tandcl.homemail.com.au/index.html, then I coudl assume that the site
had been entered from the home page.

Check the document.referrer:

if (document.referrer.indexOf('tandcl.homemail.com.au')){
alert('you got here from my site')
}

The document.referrer only works if it is opened via link though.
Otherwise, it will be empty. Meaning, if it is opened in a new window -
via script - the document.referrer will still be empty.
But I have tried alert(history(0)) and alert(history[0]) - neither works.
One gives undefined the other gives nothing (in reverse order, I think).

You have no access to what sites may or may not be in the history trail.
In the meantime, I have put a Home button on most pages with
onclick="location.href='index.html'". On other pages, I have just put a
Close button.

A Close button? Why? If the page wasn't opened via script then you can't
close it with script.
 
Trevor said:
Is there a way to detect whether a page has been opened from
another page in the same site?

You could set a transient cookie on your main page and check for it on
others. That will certainly indicate whether users reached your main page.

As to the specific question, the HTTP_REFERER header or document.referrer
property is a useful indicator.

In either case, the browser may not comply. Users can turn off either
feature in the browser.


I thought of searching the History array and if there existed
an entry for http://tandcl.homemail.com.au/index.html, then I
coudl assume that the site had been entered from the home page.

Major privacy invasion. Would *YOU* use a browser that allowed any site to
see where else you had been?



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
JRS: In article <[email protected]>, dated Tue, 7
Mar 2006 17:22:09 remote, seen in
t said:
Is there a way to detect whether a page has been opened from another page in
the same site?

If there were, then I could put up a message saying "The Home Page of this
site is ...." together with a button to click to get there.


Put a Home button or a Home link on every page, visibly but non-
obtrusively.

Those who have arrived via your Home Page may want to return there, just
as those who have come from elsewhere may or may not be interested in
your Home Page.

Also, if your site covers diverse topics, give each page a link to its
topic index page.

IMHO, for most sites, every page should be self-documenting; then, if a
page is saved, the saver can later determine its context.
 
Thanks, Randy

Randy said:
Check the document.referrer:

if (document.referrer.indexOf('tandcl.homemail.com.au')){
alert('you got here from my site')
}

Sounds good
The document.referrer only works if it is opened via link though.
Otherwise, it will be empty. Meaning, if it is opened in a new window
- via script - the document.referrer will still be empty.

Hmm!
I guess if was opened via a script, then that script would have been one on
my site.
So I would not be able to tell the difference between someone getting to a
page via a script on my site or getting there directly.
I may have scripts that open pages (I need to check), so I need to thnk
about this approach .
But I have tried alert(history(0)) and alert(history[0]) - neither
works. One gives undefined the other gives nothing (in reverse
order, I think).

You have no access to what sites may or may not be in the history
trail.

OK you have confirmed what I thought
A Close button? Why? If the page wasn't opened via script then you
can't close it with script.

I use onclick= "window.opener=self;window.close()"
These are just trivial (or "mickey-mouse") pages like this one
http://tandcl.homemail.com.au/dayborn.html
which don't really need a link back to the Home Page although in come cases
there are both a Close and a Home button
 
Dr said:
Put a Home button or a Home link on every page, visibly but non-
obtrusively.

Those who have arrived via your Home Page may want to return there,
just as those who have come from elsewhere may or may not be
interested in your Home Page.

Also, if your site covers diverse topics, give each page a link to its
topic index page.

IMHO, for most sites, every page should be self-documenting; then, if
a page is saved, the saver can later determine its context.

Thanks,
Good ideas (no doubt gleaned from your vast experience).

This is the way I was leaning - a Home link on every page, that is.
 
Randy said:
Check the document.referrer:

if (document.referrer.indexOf('tandcl.homemail.com.au')){
alert('you got here from my site')
}
....
The document.referrer only works if it is opened via link though.
Otherwise, it will be empty. Meaning, if it is opened in a new window
- via script - the document.referrer will still be empty.

Randy,
I did some tests and I am confused

When the page was called by a script with this in the <head> section:
<script type="text/javascript">
if (document.referrer.indexOf('tandcl.homemail.com.au')){
alert('you got here from my site')}
</script>
the alert appeared.

I also coded this into a close button
<input type="button" value="Close"
onclick="alert(document.referrer.indexOf('tandcl.homemail.com.au'));
window.opener=self;window.close()" />
When I clicked this, the alert gave -1 and the window then closed.

When the page was called directly, the alert did not appear,
but alert(document.referrer.indexOf('tandcl.homemail.com.au')) still gave -1

Shouldn't both ways of opening it give the same result ?
 
Trevor L. said the following on 3/7/2006 11:36 PM:
Randy,
I did some tests and I am confused

When the page was called by a script with this in the <head> section:
<script type="text/javascript">
if (document.referrer.indexOf('tandcl.homemail.com.au')){
alert('you got here from my site')}
</script>
the alert appeared.

I also coded this into a close button
<input type="button" value="Close"
onclick="alert(document.referrer.indexOf('tandcl.homemail.com.au'));
window.opener=self;window.close()" />
When I clicked this, the alert gave -1 and the window then closed.

How did you open the page that button is in? Also, document.referrer
doesn't work properly in IE off-line.
When the page was called directly, the alert did not appear,
but alert(document.referrer.indexOf('tandcl.homemail.com.au')) still gave -1

-1 means that it doesn't appear in document.referrer
Shouldn't both ways of opening it give the same result ?

Yes. But test it from a server as IE doesn't set the document.referrer
property properly when tested locally.
 
Thanks, Randy

in-line

Randy said:
Trevor L. said the following on 3/7/2006 11:36 PM:

How did you open the page that button is in? Also, document.referrer
doesn't work properly in IE off-line.

I was on-line, i.e. local disk
-1 means that it doesn't appear in document.referrer

Sorry, I knew it meant false. That was why I was confsued
Yes. But test it from a server as IE doesn't set the document.referrer
property properly when tested locally.

OK.
If I want to perservere, I'll put up the test page on the web.

Meantime, I am following Dr John's advice and putting a Home button on each
page (or a Back button to the calling page). Except in a few cases where it
is just a Close button.
 
Sorry, I knew it meant false. That was why I was confsued


Nope, -1 does not mean false.

In the context of an if statement, -1 means true. try this:

if (-1)
{
alert(-1)
}

In the context of an indexOf search, -1 means no matches found.

This code will not work as you expect:
if (document.referrer.indexOf('tandcl.homemail.com.au')){
alert('you got here from my site')
}

but this will:

if (document.referrer.indexOf('tandcl.homemail.com.au') > -1)
{
alert('you got here from my site')
}

good luck!

-ivan.
 
gilly3 said:
Nope, -1 does not mean false.

In the context of an if statement, -1 means true. try this:

if (-1)
{
alert(-1)
}

In the context of an indexOf search, -1 means no matches found.

This code will not work as you expect:


but this will:

if (document.referrer.indexOf('tandcl.homemail.com.au') > -1)
{
alert('you got here from my site')
}

good luck!

-ivan.

Strange,
Can you explain the operation of the IF statement.

My understanding was that a value of -1 is false and anything else is true.
Why does IF diifer ?
What is the logic behind:
if (-1) alert (-1)
It certainly returns an alert with -1 displayed

I also tried
if (0) alert (0)
Nothing happened.
 
In an if statement, 0 is false, any other value is true.

In a search, the search returns the character the search string is
found at. Since the first character in a string is at position 0, a
return of 0 indicates the search string was found, so the search
returns -1 to indicate not found.

The statement document.referrer.indexOf('tandcl.homemail.com.au')
will return a value >=0 if the search string 'tandcl.homemail.com.au'
is found in the document.referrer, or -1 if not
The if looks at the returned value: -1 or a value >0 means TRUE or
found, and 0 means FALSE or not found.
Hence the result from the if statement is meaningless, unless you
modify it by adding >-1 to the equation.

if(-1) always evaluates to TRUE, hence the alert.
if(0) evaluates to FALSE, and no alert.
 
Ronx wrote on 10 mrt 2006 in microsoft.public.scripting.jscript:
In an if statement, 0 is false, any other value is true.

Define statement. No thids is not true:

When a numbr is forsefully converted to an expressionresult needing the
boolean true/false, THEN and only then 0 in converted to false, and not 0
to true.
In a search, the search returns the character the search string is
found at. Since the first character in a string is at position 0, a
return of 0 indicates the search string was found, so the search
returns -1 to indicate not found.

But not found and found do not mean falde or true.

..indexOf() always returns a number, 0 vor pos 1, -1 for not found

If you want to get false for not found, you will have to manipulate

r = ....indexOf(...)
if (r+1) alert('found')

or

r = ....indexOf(...)
if (r>=0) alert('found')

The statement document.referrer.indexOf('tandcl.homemail.com.au')
will return a value >=0 if the search string 'tandcl.homemail.com.au'
is found in the document.referrer, or -1 if not
The if looks at the returned value: -1 or a value >0 means TRUE or
found, and 0 means FALSE or not found.

No, the "if" looks for a boolean, and any numeric string i converted to
that
Hence the result from the if statement is meaningless, unless you
modify it by adding >-1 to the equation.

No, it just means what it does. If jou do not know the specs by hart,
the results could be meaningless to YOU.
if(-1) always evaluates to TRUE, hence the alert.
if(0) evaluates to FALSE, and no alert.

This suggests -1 means true like in languages without boolean values,
like older Basic implementations.

Those languages had their primitive advanages:

r = 12 * ((a=3)+1) + 6 * ((a=4)+)

[((a=3)+1) meaning one if a=3, else 0]

meaning:

r=0
if a=3 then r = r + 12
if a=4 then r = r + 6

r can be 0 or 6 or 12 or 18

in jscript, of you [stubbornly but legally] wish
to use the zero to false translation:

r = (a-3) ? 0 : 12
r += (a-4) ? 0 : 6

or better readable and more "modern":

r = (a==3) ? 12 : 0
r += (a==4) ? 6 : 0

or

r = 0
(a==3) r += 12
(a==4) r += 6
 
Evertjan. said:
When a numbr is forsefully converted to an expressionresult
needing the boolean true/false, THEN and only then 0 in
converted to false, and not 0 to true.

Except, of course, when isNaN(numbr):

0/0 = NaN
typeof 0/0 = 'number'

Your description is true for any possible index value, however.



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
Dave Anderson wrote on 10 mrt 2006 in microsoft.public.scripting.jscript:

.... forcefully ..
Except, of course, when isNaN(numbr):

I was talking about a number, which is never NaN, me thinks ;-)
 
Evertjan. said:
I was talking about a number, which is never NaN, me thinks ;-)

Why do you think I included this?

NaN is indeed a number.


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
Dave Anderson wrote on 10 mrt 2006 in microsoft.public.scripting.jscript:
Why do you think I included this?


NaN is indeed a number.

According to type it is.
According to name it is not.

Indeed ;-}
 
Evertjan. said:
According to type it is.
According to name it is not.

var NotIronic = (typeof 0/0 == "number")



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
Ronx said:
In an if statement, 0 is false, any other value is true.

In a search, the search returns the character the search string is
found at. Since the first character in a string is at position 0, a
return of 0 indicates the search string was found, so the search
returns -1 to indicate not found.

The statement document.referrer.indexOf('tandcl.homemail.com.au')
will return a value >=0 if the search string 'tandcl.homemail.com.au'
is found in the document.referrer, or -1 if not
The if looks at the returned value: -1 or a value >0 means TRUE or
found, and 0 means FALSE or not found.
Hence the result from the if statement is meaningless, unless you
modify it by adding >-1 to the equation.

if(-1) always evaluates to TRUE, hence the alert.
if(0) evaluates to FALSE, and no alert.

Thanks, Ron.

I understood that, but the other repsonses have confused me

Can I rely on your reply?
 
The other responses seem to have gone off at a tangent to the original
context. I believe my response is correct.
 
Back
Top