Forums / General Questions / Using 'title' and 'alt' for images and info

Using 'title' and 'alt' for images and info

Locked

Views: 997

Results 1 to 6 of 6
This thread is locked. New replies are disabled.
28 Oct 2006, 9:16 PM
#1
chufty_bill avatar

chufty_bill

Zen Follower

Join Date:
Aug 2006
Location:
UK
Posts:
115
Plugin Contributions:
0

Using 'title' and 'alt' for images and info

Hi.

Just a quickie really.

Trying to optimize things on my site (Using 'alt' & 'title' attrib on images etc)

Just cant work out which is best to use. Sometimes they display OK in IE6 other times not. I wanted to use these attribs for warning people if a link is going to open up in a new window, and similar.

Is there an attribute function that will display an 'alternative text pop up' in all browsers?

Thanks for any advice.
Chris


28 Oct 2006, 9:42 PM
#2
lloyd_borrett avatar

lloyd_borrett

Zen Follower

Join Date:
Mar 2006
Location:
Rosebud, Victoria, Australia
Posts:
308
Plugin Contributions:
2

Re: Using 'title' and 'alt' for images and info

G'day Chris,

I always put both the alt and title attributes on images, and the title attribute on links. Then you cover all of the browsers as best you can.

I've also used the following Javascript on some sites to change the title attribute to indicate if the link will open in a new window.

function fixLinks()
{
  if (!document.getElementsByTagName) return null;
  var server = document.location.hostname;
  var anchors = document.getElementsByTagName("a");
  var i, href, title;
  for(i=0; i < anchors.length; i++){
    if(!anchors[i].href) continue;
    href = anchors[i].href;
    title = anchors[i].title;
    if(href.indexOf(server) == -1){ // Href is not a file on my server
      if(href.indexOf("javascript:") == -1){ // Href is not a javascript call
        if(!anchors[i].onclick){ // Href does not have an onclick event
          if(href.indexOf("mailto:") == -1){ // Href is not a mailto:
            if((href.indexOf("http://") != -1) || (href.indexOf("https://") != -1)){ // Href is not relative (for Safari)
              anchors[i].setAttribute("target","_blank");
              anchors[i].setAttribute("title",title + " [This Link Will Open in a New Window] ");
            }
          }
        }
      }
    }
  }
  return null;
}
window.onload.actions.push(fixLinks);

Best Regards, Lloyd Borrett.

Zen Cart 1.5.5e, PHP 5.3.29 MySQL 5.5.42

28 Oct 2006, 10:31 PM
#3
chufty_bill avatar

chufty_bill

Zen Follower

Join Date:
Aug 2006
Location:
UK
Posts:
115
Plugin Contributions:
0

Re: Using 'title' and 'alt' for images and info

Hi Lloyd.

Thanks for the reply.
Trying to cover all angles in different browsers is no walk in the park!

As a novice, the javascript you suggested:
Can I just paste this at the top of pages? Where?
Do I need to enter some javascript coding before? Etc, Etc, :blush:

I dont know javascript Im afraid, although I have seen it in places.

Many thanks
Hope your site and the CSS flyout thing has worked out OK for you.
Regards Chris


28 Oct 2006, 10:39 PM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Using 'title' and 'alt' for images and info

You can accomplish it site-wide by dumping it into a jscript_mylinks.js file in your template folder, as per this article:
http://www.zen-cart.com/wiki/index.php/Customisation_-_Templates_-_Javascript

That way you won't have to touch any core files.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

28 Oct 2006, 10:45 PM
#5
lloyd_borrett avatar

lloyd_borrett

Zen Follower

Join Date:
Mar 2006
Location:
Rosebud, Victoria, Australia
Posts:
308
Plugin Contributions:
2

Re: Using 'title' and 'alt' for images and info

G'day Chris,

Actually, I haven't tried using that Javascript on my Zen Cart sites as yet. I'm still in the process of building them. (Sorry, I should have pointed that out.)

As that Javascript code would be needed on every page in the site, if I was to add it to Zen Cart, I'd probably start by looking at how Zen Cart loads Javascripts.

I think the template overrides system lets you put the script file in /includes/templates/YOURTEMPLATE/jscript with a filename jscript_YOURSCRIPTNAME.php and then Zen Cart automatically loads it into every page. But this is something I haven't yet tried with Zen Cart, so I can't guarantee that.

EDIT: What DrByte said above is likely to be a more definitive answer. He should know.

Best Regards, Lloyd Borrett.

Zen Cart 1.5.5e, PHP 5.3.29 MySQL 5.5.42

29 Oct 2006, 9:21 AM
#6
chufty_bill avatar

chufty_bill

Zen Follower

Join Date:
Aug 2006
Location:
UK
Posts:
115
Plugin Contributions:
0

Re: Using 'title' and 'alt' for images and info

Hi

Thank you both.

Will set it in action!

Regards Chris