Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #14411 > unrolled thread
| Started by | Gene Wirchenko <genew@ocis.net> |
|---|---|
| First post | 2012-06-08 14:11 -0700 |
| Last post | 2012-06-09 23:20 +0100 |
| Articles | 6 — 5 participants |
Back to article view | Back to comp.lang.javascript
The links Collection Gene Wirchenko <genew@ocis.net> - 2012-06-08 14:11 -0700
Re: The links Collection Matt McDonald <matt@fortybelow.ca> - 2012-06-08 15:48 -0600
Re: The links Collection SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-06-09 08:35 +0200
Re: The links Collection Dr J R Stockton <J.R.Stockton@physics.org> - 2012-06-09 08:39 -0700
Re: The links Collection Dr J R Stockton <J.R.Stockton@physics.org> - 2012-06-09 11:49 -0700
Re: The links Collection Dr J R Stockton <reply1223@merlyn.demon.co.uk.not.invalid> - 2012-06-09 23:20 +0100
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2012-06-08 14:11 -0700 |
| Subject | The links Collection |
| Message-ID | <k5q4t7ld2khdqp1kb5pl71vto38u7l8hji@4ax.com> |
Dear JavaScripters:
I am working through another Web book. It has an example with
the links collection. I am trying to understand how the links
collection works. Unfortunately, the book does not explain the link
collection in detail, and I have been unable to find anything of help
on the Web.
The code, at body onload, builds a copy of all of the links on
the page and inserts that at the bottom. Here is the relevant,
puzzling code:
Contents+=
"<span class=link>"+
document.links[i].innerHTML.link(document.links[i].href)+
"</span> | ";
document.links[i]
refers to a particular link. Its .innerHTML appears to be just a
string so why would it have a .link property? And having specified
which link at the start, why does it have to be specified again for
the .href?
Does anyone have a pointer to a page that describes the links
properties in detail? All I have been able to find does not cover any
more than the first bit.
Sincerely,
Gene Wirchenko
[toc] | [next] | [standalone]
| From | Matt McDonald <matt@fortybelow.ca> |
|---|---|
| Date | 2012-06-08 15:48 -0600 |
| Message-ID | <jqtrum$46i$1@dont-email.me> |
| In reply to | #14411 |
On 12-06-08 03:11 PM, Gene Wirchenko wrote: > [...] I am trying to understand how the links > collection works. Unfortunately, the book does not explain the > link collection in detail, and I have been unable to find > anything of help on the Web. There's not a whole lot of detail required. What book are you sourcing this code from? > [...] refers to a particular link. Its .innerHTML appears to > be just a string so why would it have a .link property? And > having specified which link at the start, why does it have to > be specified again for the .href? You are reading a use of `String.prototype.link`[0], which is a non-standard property. The CLJ FAQ coincidentally states[1] the following. > Nonstandard built-in objects may include RuntimeObject, > **String.prototype.link**, CollectGarbage, and more. > Does anyone have a pointer to a page that describes the links > properties in detail? All I have been able to find does not > over any more than the first bit. (assuming information about `HTMLDocument::links` is being requested) The DOM Level 2 HTML Specification states[2] the following. > A collection of all AREA elements and anchor (A) elements > in a document with a value for the href attribute. As I wrote earlier, there's not a whole lot of detail required. [indentation removed and quotations trimmed] [0]: https://developer.mozilla.org/en/JavaScript/ Reference/Global_Objects/String/link [1]: http://www.fortybelow.ca/hosted/ comp-lang-javascript/faq/#builtInObject [2]: http://www.w3.org/TR/DOM-Level-2-HTML/ html.html#ID-7068919 -- Matt McDonald: Web/Flash Developer; Edmonton, Alberta, Canada
[toc] | [prev] | [next] | [standalone]
| From | SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> |
|---|---|
| Date | 2012-06-09 08:35 +0200 |
| Message-ID | <4fd2eec5$0$6176$ba4acef3@reader.news.orange.fr> |
| In reply to | #14411 |
Le 08/06/12 23:11, Gene Wirchenko a écrit :
>
> The code, at body onload, builds a copy of all of the links on
> the page and inserts that at the bottom. Here is the relevant,
> puzzling code:
>
> Contents+=
> "<span class=link>"+
> document.links[i].innerHTML.link(document.links[i].href)+
> "</span> | ";
>
> document.links[i]
> refers to a particular link. Its .innerHTML appears to be just a
> string so why would it have a .link property? And having specified
> which link at the start, why does it have to be specified again for
> the .href?
you got the answer given by Matt :
<https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/link>
A more laborious way using grand Ma's JS,
a script to put at end of body :
var a = document.links, n = a.length, c = 0, t = '';
while(c<n) {
t += '<a href="' + a[c].href + '">' + a[c].text + '<\/a> | ';
c++
}
document.open();
document.write('<span class="link">' + t + '<\/span>');
document.close();
Another one using more "modern" JS and not less laborious :
var a = document.links,
n = a.length,
c = document.createElement('spam'),
t;
c.className = 'link';
while(n--) {
t = document.createElement('a');
t.href = a[n].href;
t.innerHTML = a[n].innerHTML; // or : t.text = a[n].text;
c.appendChild(t);
c.appendChild(document.createTextNode(' | '));
}
document.body.appendChild(c);
--
Stéphane Moriaux avec/with iMac-intel
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <J.R.Stockton@physics.org> |
|---|---|
| Date | 2012-06-09 08:39 -0700 |
| Message-ID | <7ac8d48f-c67e-431b-b003-751807b75cb7@fr28g2000vbb.googlegroups.com> |
| In reply to | #14411 |
On Jun 8, 10:11 pm, Gene Wirchenko <ge...@ocis.net> wrote: > I am working through another Web book. It has an example with > the links collection. I am trying to understand how the links > collection works. Read the code of <http://www.merlyn.demon.co.uk/linxchek.htm>, in particular the call chain to and the contents of function ProcessLinks. There is a heap of buttons at the bottom, and you should be able to see which one to press (in addition to View Source). The main code of the page will only run for a local copy of the page; and for real success it will prove necessary to have read the instructions. You might find it useful; and it would be of interest to see how far you get. OTOH, adequate details are in Flanagan "Dynamic HHML" 3rd - and, I dare say, in other editions too. The code used in <http://www.merlyn.demon.co.uk/js-props.htm> would enable inspection of the link objects themselves, if modified to index into their collections. -- (c) John Stockton, near London, UK. Using Google, no spell-check. Mail: J.R.""""""""@physics.org or (better) via Home Page at Web: <http://www.merlyn.demon.co.uk/> FAQish topics, acronyms, links, etc.; Date, Pascal, JavaScript, ....|
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <J.R.Stockton@physics.org> |
|---|---|
| Date | 2012-06-09 11:49 -0700 |
| Message-ID | <88e9ea29-6fb2-4d99-a1ea-33a346aab510@q29g2000vby.googlegroups.com> |
| In reply to | #14411 |
On Jun 8, 10:11 pm, Gene Wirchenko <ge...@ocis.net> wrote:
> The code, at body onload, builds a copy of all of the links on
> the page and inserts that at the bottom.
See the bottom of <http://www.merlyn.demon.co.uk/index.htm>, the
following function in my inc-cmmn.js, and in index.htm (now altered)
<pre ID=Lynx class=OUT></pre>
<script type="text/javascript">Wryt("Lynx", ListLinks())</script>
function ListLinks() {
var LINKS = [], DL = document.links, L = DL.length, J, T="", X
for (J=0 ; J<L ; J++) LINKS.push(DL[J].href.replace(/#.*/, ""))
LINKS.sort()
J = 0 ; while (J<LINKS.length) {
X = LINKS[J]
if (X==T) LINKS.splice(J, 1) ; else J++ // de-dupe
T = X }
LINKS.splice(0, 0, "Automatic List of Links on This Page", "")
return LINKS.join("\n") }
Readers may reproduce that function in their code with
acknowledgement, but may not link to where I keep it and may not
republish it.
--
(c) John Stockton, near London, UK. Using Google, no spell-check.
Mail: J.R.""""""""@physics.org or (better) via Home Page at
Web: <http://www.merlyn.demon.co.uk/>
FAQish topics, acronyms, links, etc.; Date, Pascal, JavaScript, ....|
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <reply1223@merlyn.demon.co.uk.not.invalid> |
|---|---|
| Date | 2012-06-09 23:20 +0100 |
| Message-ID | <UVx6s+suw80PFwk$@invalid.uk.co.demon.merlyn.invalid> |
| In reply to | #14411 |
In comp.lang.javascript message <k5q4t7ld2khdqp1kb5pl71vto38u7l8hji@4ax. com>, Fri, 8 Jun 2012 14:11:01, Gene Wirchenko <genew@ocis.net> posted: Yes, I know the Demon Web server is broken. > I am working through another Web book. Title, author, etc.? -- (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike 6.05 WinXP. Web <http://www.merlyn.demon.co.uk/> - FAQ-type topics, acronyms, and links. Command-prompt MiniTrue is useful for viewing/searching/altering files. Free, DOS/Win/UNIX now 2.0.6; see <URL:http://www.merlyn.demon.co.uk/pc-links.htm>.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web