PDA

View Full Version : HTML Question



tony5429
March 19th, 2008, 05:44 PM
I am using the following format for links on a web site I am working on...



<a href=http://google.com onFocus="if(this.blur)this.blur()">Google</a>


Rather than type that onFocus part into every link, is there a way I can put something in the header at the top that applies that to all links in the page? The command removes that little annoying selection rectangle on clicked links.

LaRoza
March 19th, 2008, 06:07 PM
I am using the following format for links on a web site I am working on...



<a href=http://google.com onFocus="if(this.blur)this.blur()">Google</a>


Rather than type that onFocus part into every link, is there a way I can put something in the header at the top that applies that to all links in the page? The command removes that little annoying selection rectangle on clicked links.

Yes, such declarations are messy. (See my homepage for use of scripting in a clean way. ALL script is in a separate file.)

You can do the same, link to this script as is, and it will apply that to every link in the page:



window.onload = function()
{
var linds = document.getElementsByTagName("a");
//This loop should be executed IF linds exists, so it should be encapsulated in "if (linds && document.getElementsByTagName) {....}"
for (var i = 0; i < linds.length; i++)
{
linds[i].onfocus = function()
{
if (this.blur)
{
this.blur();
}
}
}
}

lnostdal
March 19th, 2008, 06:14 PM
you might like jQuery .. it's small and simple



$("a").focus(function(){
if(this.blur){
this.blur()
}
}

Zugzwang
March 19th, 2008, 06:14 PM
Just a question: Doesn't this make a page unusable for keyboard-only navigation? If yes, you shouldn't bother with the selection boxes due to accessibility issues.

(EDIT: This question refers to the original posting)

leg
March 19th, 2008, 07:09 PM
Just a question: Doesn't this make a page unusable for keyboard-only navigation? If yes, you shouldn't bother with the selection boxes due to accessibility issues.

(EDIT: This question refers to the original posting)
Yes it does and the op should have a very good reason to do this. If not then he should not do it.