Forum Moderators: open

Message Too Old, No Replies

Using Javascript to ad an image next to every link on a page

Just can't get started....

         

dataguy

1:20 pm on May 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am in the middle of a project which will require javascript to add an image next to every link which appears on a page. The link URL will then be added as a querystring to the image name so that the link URL can be read from a remote server (the one serving the image).

I think this is the best way to accomplish what I need, but I'm having problems getting started with the javascript. I know I need to "walk the DOM" but I can't find any examples that I can modify to do what I need.

Can someone point me in the right direction or at least give me some suggestions for keywords to search on to find an example?

bumpski

8:17 pm on May 12, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Dataguy

Yes "Walking the DOM" can have quite a learning curve.

One short cut is simply using "document.write()". This routine will insert any html you want inline in your document. So if you know html you can insert javascripts in your files where you need them.
You will also have to manipulate strings, but that is less complicated than working with the "DOM". The killer with the DOM and javascript is the variances from standards. To be fair, quite a bit of this "stuff" html was created before the standards truly existed.

Here are some references (that should me TOS):
[developer.mozilla.org...]

Oddly enough Microsoft documents are quite good in some regard:
[msdn.microsoft.com...]
See this specifically for a short (very) intro.
[msdn.microsoft.com...]
[msdn.microsoft.com...]

Microft's MSDN reference actually documents the elements and their javascript interface well. At the bottom of each page in this reference is an indication whether it is standards compliant or not. There are many non-compliant extensions in the above msdn reference. These are things you will find that may not work in firefox, netscape, etc.
The "samples" are worthwhile but you'll have to use IE to see the samples!

And of course there is the World Wide Web consorteium that documenter of the standards
[w3.org...]
What's annoying is they have created excellent standards but they are not very good at telling you how to use them. (That's the standards world!)