views:

314

answers:

8

is there any script which can stop to show ALT="text" as a tooltip in IE 6 and 7?

A: 

You could do the following but it would be very intrusive (and a bit slow):

$('*').attr('alt', '');
cherouvim
but i don't want to remove alt text from source code.
metal-gear-solid
This doesn't remove it from the source code, but from the DOM which is in memory. Bots will not be affected, and you could couple this with a jQuery.support call in order to execute it only on IE6 and IE7
cherouvim
Sidenote: This is jQuery notation.
Boldewyn
@Boldewyn: yes it is but I saw the jQuery tag so I thought that the author uses jQuery anyway
cherouvim
+3  A: 

I wouldn't worry too much about it. It's a known bug and it's fixed in IE8.

Heinzi
if i add title and alt both on a image then what will be show on mouseover?
metal-gear-solid
title​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​.
bobince
Well, since IE6 is **still** the most used browser...
kemp
@Kemper: Sad, but true. Still, considering the work involved to make a page IE6-compatible, I think it's OK if a site looks "a little bit less nice" in IE6, as long as its main functionality works.
Heinzi
Would be sad, but not true. IE6 is certainly not the most used browser anymore, not even during the weekday daytime hours.
treeface
+1  A: 
$$('img').set('alt', '');

No other way, apart from setting the title attribute.

Oskar Krawczyk
Sidenote: This is Prototype (a JS framework) notation.
Boldewyn
+3  A: 
$('img').each(function (i, el) {
  if (!el.hasAttribute('title')) {
    el.setAttribute('title', '');
  }
});

That should give all images without a title attribute an empty one. I'm not sure if it will fix the problem for IE6 and IE7 but I think they support title and this might override it.

Eli Grey
Can anyone verify this?
Boldewyn
A: 

Presumably for alt attribute, you just mean image elements?

$('img').removeAttr('alt');

You may also consider removing the title attribute from elements in the DOM

$('*').removeAttr('title');
Russ Cam
+2  A: 
<!--[if IE]><script>for(i =0;i<document.images.length;i++){document.images[i].alt='';}</script><![endif]-->

at the end of the page should do it.

vsr
yes it work but first time it shows activex message on top
metal-gear-solid
"To help protect your security, Internet Explorer has restricted this file from showing active content that could access your computer. Click here for options"
metal-gear-solid
@Jitendra I guess you are running it on local machine. Read more about the warning message at http://www.psychpage.com/tech/damnbar.html
vsr
+1 for conditional comments.
Boldewyn
@VSR - will this script slow down page rendering?
metal-gear-solid
This will remove the alternative text from any screen reader running over IE (so it is a really bad idea)
David Dorward
A: 

Do screan reader run javascript? If not then why bother with this mod?

Setting alt to "" would hide the alt "tooltip" in IE < 8 which seems to be all you are after. Plus this should be done anyway for all image or else screen readers have a habit of of rendering out a default "image placeholder" speech. If you set it to blank then it won't bother and will skip it, ideal for images that are simply used for design rather than content.

Unfortunately there is no special flag or switch you can flick via JS or any other method to tell IE to behave any differently in this regard which is what I believe you are asking for.

An alternative is to switch any alts you find in images to be titles but this does not get rid of the tooltips, you just end up making them appear in all browsers then rather than just IE.

So the final fix is to simply clear all alt attributes in images (and there are scripts in other answers here that do just that). You asked the question but I think you should ponder about what it is you are trying to achieve and more importantly, why and is it that essential?

Pete Duncanson
+1  A: 

In IE before IE8 the only way to avoid the browser to show images alt text as tooltip are:

  1. not to use the alt attribute (which is not a good idea because it's not valid HTML and it's not good even for Google SEO and text readers that can not see your images).

  2. place in each image a title="" empty attribute.

In order to accomplish point (2) using a simple Javascript with no jQuery, you have to place this small piece of code before ending BODY tag, like this:

   <!--[if lt IE 8]>
      <script>
         for(var i = 0, imgs = document.images, len = imgs.length; i < len; ++i)
            if(!imgs[i].title)
               imgs[i].title = "";
      </script>
   <![endif]-->            
</body>

You can write it in one line if you prefer.

The advantaghe of this code is that it does not screw up the alt tag attributes of your images, it simply sets the title attribute to empty string, unless a title attribute is already defined in this last case I suppose the title attribute was defined because you want to show whatever you wrote in title attribute as a tooltip (which is a cross-browser behaviour).

Marco Demajo