Cuffs - code and effect comment?

D

Dr J R Stockton

<URL:http://www.merlyn.demon.co.uk/js-index.htm>, and js-dates.htm, and
some Easter pages, now include <BODY onload="Cuffs()">.

function Cuffs() { var ThisPage, ThisSite, J, DLJ, HREF
ThisPage = location.href.replace(/#.*/, "")
ThisSite = location.protocol + "//" + location.hostname + "/"
for (J in document.links) {
DLJ = document.links[J] ; HREF = DLJ.href
if (!HREF) continue // why an undefined ?
HREF = String(HREF)
if (HREF.indexOf(ThisPage) == 0) DLJ.title = "." ;
else if (HREF.indexOf(ThisSite) == 0) DLJ.title = "+" ;
else if (HREF.indexOf("http://") == 0) DLJ.title = "#" ;
else DLJ.title = "*" } }

Comment on the code or its effect?

Why does HREF = String(HREF) seem needed?

Only tested in XP sp2 IE6 & FF 2.0.0.3.
 
R

ron.h.hall

<URL:http://www.merlyn.demon.co.uk/js-index.htm>, and js-dates.htm, and
some Easter pages, now include <BODY onload="Cuffs()">.

function Cuffs() { var ThisPage, ThisSite, J, DLJ, HREF
ThisPage = location.href.replace(/#.*/, "")
ThisSite = location.protocol + "//" + location.hostname + "/"
for (J in document.links) {
DLJ = document.links[J] ; HREF = DLJ.href
if (!HREF) continue // why an undefined ?
HREF = String(HREF)
if (HREF.indexOf(ThisPage) == 0) DLJ.title = "." ;
else if (HREF.indexOf(ThisSite) == 0) DLJ.title = "+" ;
else if (HREF.indexOf("http://") == 0) DLJ.title = "#" ;
else DLJ.title = "*" } }

Comment on the code or its effect?

Why does HREF = String(HREF) seem needed?

That would be due to the fact that your iteration construct causes all
properties of the document.links object to be included, many of which
you do not wish to access. Try

for ( J = 0; J < document.links.length; ++J ) {
...
}
 
S

scripts.contact

function Cuffs() { var ThisPage, ThisSite, J, DLJ, HREF
ThisPage = location.href.replace(/#.*/, "")
ThisSite = location.protocol + "//" + location.hostname + "/"
for (J in document.links) {
DLJ = document.links[J] HREF = DLJ.href
if (!HREF) continue // why an undefined ?
HREF = String(HREF)
if (HREF.indexOf(ThisPage) == 0) DLJ.title = "." ;
else if (HREF.indexOf(ThisSite) == 0) DLJ.title = "+" ;
else if (HREF.indexOf("http://") == 0) DLJ.title = "#" ;
else DLJ.title = "*" } }

Comment on the code or its effect?

Why does HREF = String(HREF) seem needed?

function Cuffs() {
var ThisPage,ThisSite,J,DLJ,HREF;
var l=location,links=document.links;
ThisPage = l.protocol+'//'+l.host+l.pathname+l.search
ThisSite = l.protocol+"//"+location.hostname+'/';
for(J=0;J<links.length;J++){
DLJ = links[J];
HREF = DLJ.href;
if (HREF.indexOf(ThisPage) == 0)
DLJ.title = ".";
else if (HREF.indexOf(ThisSite) == -1)
DLJ.title = "+";
else if (HREF.indexOf("http://") == -1)
DLJ.title = "#";
else DLJ.title = "*"
}
}
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
oglegroups.com>, Thu, 24 May 2007 17:55:06, (e-mail address removed) posted:
That would be due to the fact that your iteration construct causes all
properties of the document.links object to be included, many of which
you do not wish to access. Try

for ( J = 0; J < document.links.length; ++J ) {

I've been able to return to this code (which is now used in most of
those of my pages which use the corresponding Include file).

Understood; tested; OK; thanks.
 
R

ron.h.hall

In comp.lang.javascript message <[email protected]
oglegroups.com>, Thu, 24 May 2007 17:55:06, (e-mail address removed) posted:




I've been able to return to this code (which is now used in most of
those of my pages which use the corresponding Include file).

Understood; tested; OK; thanks.

All's swell that mends well. You're welcome!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,160
Messages
2,570,889
Members
47,422
Latest member
LatashiaZc

Latest Threads

Top