f



Cuffs - code and effect comment?

<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.

-- 
 (c) John Stockton, Surrey, UK.  ?@merlyn.demon.co.uk   Turnpike v6.05   IE 6
 news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
 <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
 <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
0
jrs (46)
5/24/2007 9:46:22 PM
comp.lang.javascript 38370 articles. 2 followers. javascript4 (1315) is leader. Post Follow

4 Replies
29464 Views

Similar Articles

[PageSpeed] 35

On May 24, 2:46 pm, Dr J R Stockton <j...@merlyn.demon.co.uk> wrote:
> <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 ) {
       ...
    }


 --
    ../rh


0
ron
5/25/2007 12:55:06 AM
On May 24, 3:46 pm, Dr J R Stockton <j...@merlyn.demon.co.uk> wrote:
> 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 = "*"
  }
}


0
scripts
5/25/2007 1:57:50 AM
In comp.lang.javascript message <1180054506.240417.286470@q19g2000prn.go
oglegroups.com>, Thu, 24 May 2007 17:55:06, ron.h.hall@gmail.com posted:
>On May 24, 2:46 pm, Dr J R Stockton <j...@merlyn.demon.co.uk> wrote:
>> <URL:http://www.merlyn.demon.co.uk/js-index.htm>, and js-dates.htm, and
>> some Easter pages, now include <BODY onload="Cuffs()">.

>> 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 ) {

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.

-- 
 (c) John Stockton, Surrey, UK.  ?@merlyn.demon.co.uk   Turnpike v6.05   MIME.
 Web  <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links;
  Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
 No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
0
Dr
6/6/2007 9:34:53 PM
On Jun 6, 2:34 pm, Dr J R Stockton <j...@merlyn.demon.co.uk> wrote:
> In comp.lang.javascript message <1180054506.240417.286...@q19g2000prn.go
> oglegroups.com>, Thu, 24 May 2007 17:55:06, ron.h.h...@gmail.com posted:
>
> >On May 24, 2:46 pm, Dr J R Stockton <j...@merlyn.demon.co.uk> wrote:
> >> <URL:http://www.merlyn.demon.co.uk/js-index.htm>, and js-dates.htm, and
> >> some Easter pages, now include <BODY onload="Cuffs()">.
> >> 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 ) {
>
> 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!

--
  ../rh

0
ron
6/7/2007 1:48:36 PM
Reply: