SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: Javascript Functions and links
Hybrid View
-
Dec 18, 2001, 13:12 #1
Javascript Functions and links
Hello,
I wrote a funtion for all my <a href=...> tags.
If I use the function, it looks like this:
<a href="test.html" onFocus="myfunction()">
What I want is to automatically add myfunction() to all the links on a page. So I don't want to add onFocus=blablabla each time when I link to another page.
Any suggestions?
-
Dec 18, 2001, 19:38 #2
- Join Date
- Oct 2001
- Location
- Whistler BC originally from Guelph Ontario
- Posts
- 2,175
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This may not work but it is he only thing I could come up with.
There is an element grabber called
document.getElementByTagName('a')
you can find info on this here
http://www.webreference.com/programm...pting/1/3.html
use this like this
Code:document.getElementByTagName("a").onfocus=fucntion;
http://www.webreference.com/js/column74/
Hope this works. In theory it shouldMaelstrom Personal - Apparition Visions
Development - PhP || Mysql || Zend || Devshed
Unix - FreeBSD || FreeBsdForums || Man Pages
They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.
-
Dec 19, 2001, 04:36 #3
I've already tried that, but it seems it doesn't work in MSI6
A simple try:
Code:<script> var nule = black; document.getElementByTagName("a").style.backgroundColor=nule; </script>
-
Dec 19, 2001, 05:14 #4
- Join Date
- Oct 2000
- Location
- Austin, TX
- Posts
- 1,438
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
document.getElementByTagName returns an array, so if you iterate through each element it'll work.
ck :: bringing chris to the masses.
-
Dec 19, 2001, 06:34 #5
I recently posted a similar request on another forum for help with a catch-all function such as the one you are looking for...
My request was for a script that would kill all activation of the Internet Explorer image link focus border on a page.
I knew how to do it on a link by link basis, but wanted to add it to existing sites so wanted something that could go into the head tag with only minimal addition to the code.
He posted this:
-------------------
function unblur() {
this.blur();
}
function getLinksToBlur() {
if (!document.getElementById) return
links = document.getElementsByTagName("a");
for(i=0; i<links.length; i++) {
links[i].onfocus = unblur
}
}
and then put in the body tag:
<body onload="getLinksToBlur();">
the onload event is triggered after the page is loaded. You cannot put it just in the <head> section because if the code is executed at this point you won't have any "A" tags to 'unblur'
--------
While not knowing a great deal about what is happening in this script, I'm pretty sure both parts can be adapted to perform your function quite easily.
It worked a treat for me
Hope this helpsNew Plastic Arts: Visual Communication | DesignateOnline
Mate went to NY and all he got me was this lousy signature
-
Dec 19, 2001, 06:53 #6
- Join Date
- Oct 2001
- Location
- Whistler BC originally from Guelph Ontario
- Posts
- 2,175
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally posted by Anarchos
document.getElementByTagName returns an array, so if you iterate through each element it'll work....
Maelstrom Personal - Apparition Visions
Development - PhP || Mysql || Zend || Devshed
Unix - FreeBSD || FreeBsdForums || Man Pages
They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.
Bookmarks