HTML client-side image maps

Last update : June 24, 2014

You can create different clickable areas within an image using the usemap attribute together with the map tag. The usemap attribute of the img tag points to an map tag containing a description of the clickable areas that the map is divided into. The map tag has a id attribute to define its name, and also declares which areas are clickable by using the area tags.

An example of HTML code is shown below :

<img src="image.jpg"
	width="150"
	height="70"
	usemap="#mymap">
<map id="mymap">
	<area shape="rect"
		   href="start.html"
		   coords="0,0,48,28"
                   alt="blablabla" />

	<area shape="circle"
		   href="previous.html"
		   coords="50,30,10"
                   alt="blablabla" />

	<area shape="poly"
		   href="next.html"
		   coords="60,50,80,30,100,40,50,100"
                   alt="blablabla" />
</map>

The coordinates for the different shapes are :

  • rect (rectangle) : top left x, y ; bottom right x, y
  • circle : center x, y ; radius
  • poly (polygon) : list of x, y coordinates, separated by commas

In XHTML 1.0, the “usemap” attribute in the “img” element is defined as being a URI. This means that # (pound sign) can be used, as it specifies a link to a ‘fragment identifier’ in the current page. For the “map” element, the “id” attribute is required. In XHTML 1.1, the “usemap” attribute for the “map” element is an IDREF rather than a URI. This means that this value must be the same value as the “id” attribute of the other element.

The problem is that the valid code does’nt work in all browsers. If you want an image map that functions, you must write invalid XHTML 1.1 code. More infos about this topic are available at the Randsco website.

The name tag is required besides the id tag for the Firefox and Chrome browser’s. To embed a usemap in another HTML page, the object tag returns a wrong URL with embedded links. A workaround is to use iframes which work in most browsers.

ISMAP is part of the old-fashioned way of making image maps which originally required a server-side file as well as the HTML in the page.

We can add events (that can call a javascript) to the tags inside the image map. The tag supports the onClick, onDblClick, onMouseDown, onMouseUp, onMouseOver, onMouseMove, onMouseOut, onKeyPress, onKeyDown, onKeyUp, onFocus, and onBlur events.

A code example is shown hereafter :

<area shape =”circle” coords =”90,58,3″
onMouseOver=”writeText(‘The mouse is inside the circle.’)”
href =”about.html” target =”_blank” alt=”Blablabla” />

A useful program to set up image maps is Mapedit 4.0 5 from Boutell.com.

Unobtrusive JavaScript

The following HTML code shows the basics of modern javascript programming :

<html>
<head>
<script type=”text/javascript” src=”helloworld.js”></script>
</head>
<body>
<p id=”hello”></p>
</body>
</html>

The concept is to keep the javascript separate from the HTML of the web page and to just use a script tag in the head section of the webpage to link the two together. An id tag is used to identify the part of the body of the web page that should be updated with javascript.

The javascript code is shown below :

function sayHello() {
document.getElementById(‘hello’).innerHTML = ‘Hello World’;
}
window.onload = sayHello;

In the past the function document.write() was used for this purpose, but this is “bad form” and not valid xhtml code. To adhere to strict xhtml code, then it would be better to create elements using document.createElement and element.appendChild (and other native DOM node manipulation functions). For inserting text into an existing element, innerHTML is still acceptable code (and completely cross-browser). The “all DOM” way requires a lot of extra code, is slower, harder to maintain than simpler method and it needs more bandwidth.

“alt” and “title” attributes for images

The alt attribute is designed to be an alternative text description for images. alt text displays before the image is loaded. It is a required element for images and can only be used for image tags.

In contrast, the title attribute can be used for any page element, but it isn’t required for any page element. Many search engine ranking algorithms read the text in title attributes as regular page content.

In the past,  the alt text description was often used as a sort of pop-up tooltip on images. That was because the title attribute wasn’t widely supported. Today most browsers interpret the W3C specifications rather strictly – alt text no longer “pops up” when you run your mouse over an image. You have to use a title attribute for that.

Destroy, delete, unlink files : access denied

Sometimes there are files on a hosted server which can not be deleted by FTP even if you are logged in as the domain administrator. This happens for example when you upload a file using PHP. These files will be marked as being owned by the Apache (or Fast-CGI) user. So when you log into the FTP or the Plesk or Confixx desktop with your own user id, you can’t delete or change the files PHP has uploaded as they are owned by another user.

The only way to delete or change these files is to do it by a PHP script. In PHP you delete files by calling the unlink function.

To delete the file test.txt we simply run a PHP script that is located in the same directory.

<?php
$myFile = “test.txt”;
unlink($myFile);
?>

I had this problem a few days ago when I tried to delete an old wordpress installation on a server and it was not possible to delete the uploads folder cretaed by the wordpress application.

Speak to the web robots

Last update : July 2, 2013
Web Robots (also called crawlers, wanderers or spiders) are programs that traverse many pages in the World Wide Web by recursively retrieving linked pages. For various reasons web robots are not always welcome to access certain web pages.

web robots

Googlebot

A simple method used to exclude web robots from a server is to create a file on the server which specifies an access policy for robots. This file must be accessible via HTTP on the local URL “/robots.txt”. The contents of this file uses two records: user-agent and disallow.

It is not an official standard backed by a standards body, or owned by any commercial organisation. It is not enforced by anybody, and there no guarantee that all current and future web robots will use it. Consider it a common facility the majority of web robot authors offer the WWW community to protect web servers against unwanted accesses by their robots.

The latest version of the robots.txt document can be found on http://www.robotstxt.org/orig.html.

Another way to tell web robots what to do is the use of meta tags index and follow. Informations about these meta tags are available at the metatags.info website.

Examples :
index the whole website
<meta name="robots" content="index, follow" />
index the current page and stop there
<meta name="robots" content="index, nofollow" />
ignore the current page, but crawl the other web pages
<meta name="robots" content="noindex, follow" />
ignore the whole website
<meta name="robots" content="noindex, nofollow" />

There are more robot meta tags. Sometimes search engines uses descriptions from the ODP (Open Directory Project) as the title and snippet for a web result. The tag noodp lets you opt out of the ODP title and description. The tag noydir does the same for the Yahoo directory. The tag noarchive prevents serach engines from showing the cached link for a page. The tag nosnippet prevents a snippet from being shown in the search results. The tag noimageindex lets you specify that you do not want your page to appear as the referring page for an image that appears in Google search results.

ZenCart configuration tips

Default Tax Class :
To set a default Tax Class for new-products, find out the tax class ID number in Admin> Locations/Taxes> Tax Classes and enter this ID in the field Product Price Tax Class Default – When adding new products? in the Admin> Catalog> Product Types menu.

Weights and Prices attributes:
Attribute Prices can be entered with a prefix of + or – or blank

  • + and blank will add the attribute price
  • – will subtract the attribute price
  • When you Price by Attribute, the price you enter here will be added to your base price, whether you define a + prefix or not.

Weight can be entered optionally if it effects the product weight with a prefix of + or – or blank

  • + and blank will add the attribute weight
  • – will subtract the attribute weight

The prefixes are set in the attributes_controller webpage :

ZenCart Attributes

ZenCart Attributes

Attribute flags:
The default values for the attribute flags on the attributes_controller webpage (see image above) are set with the following options on the product type info layout webpage :

  • ARTWORK Attribute is Display Only
  • ARTWORK Attribute is Free
  • ARTWORK Attribute is Default
  • ARTWORK Attribute is Discounted
  • ARTWORK Attribute is Included in Base Price
  • ARTWORK Attribute is Required

Translations and Transliterations

Making a website available in multiple languages is important, especially if the target audience is international. Google offers two types of solutions to the Translation challenge. One is by straight online translation via a handy translation widget. The second solution is the Google AJAX Language API.

With the AJAX Language API, it’s possible to translate and detect the language of blocks of text within a webpage using only Javascript. With the AJAX Language API for Transliteration, it’s possible to enable transliteration on any textfield or textarea in a webpage. Transliteration is the process of phonetically converting a word written in one script into another. Transliteration should not be confused with translation, which involves a change in language while preserving meaning. With transliteration, it is the sound of the words that are converted from one alphabet to the other.

Code examples are available at the Google AJAX API’s Playground. A useful tutorial how to add inline language translation to a website with Google AJAX API has been written by Amit Agarwal.

WordPress themes and templates

last update : April 3, 2012
A WordPress Theme is a collection of files that work together to produce a graphical interface with an underlying unifying design for a weblog. These files are called template files. Some templates (the header.php and footer.php template files for example) are used on all the web pages, while others are used only under specific conditions.

A simple WordPress web page structure is made up of three basic building blocks: a header, the content, and a footer. The main template file is index.php, it’s function is to call other template files and to gather information from the database (posts, pages, categories, etc.) with the WordPress Loop. Most WordPress pages contain one or more sidebars (sidebar.php) that contains navigation features and more information about the website.

The Theme’s style sheet determines the look and placement of the header, footer, sidebar, and content in the user’s browser screen.

WordPress features two core page views: the single post view is used when the web pages displays a single post. The multi-post view lists multiple posts or post summaries, and applies to category archives, date archives, author archives, and (usually) the “normal” view of the blog’s home page. WordPress uses a template hierarchy to select the right template file to display a certain type of page. Template files include the use of XHTML tags and CSS references. HTML elements and CSS references can cross template files, beginning in one and ending in another. Tracking down where an HTML element begins and ends can get complicated if a Theme is designed or modified.

A very simple, but fully functional loop page (index.php) is shown below:

<?php
get_header();
if (have_posts()) :
   while (have_posts()) :
      the_post();
      the_content();
   endwhile;
endif;
get_sidebar();
get_footer();
?>

Template tags are used within the blog to display information dynamically or to customize the blog. It provides the tools to make the blog individual and interesting. The template tags are segmented as follows :

  • include tags
  • blog info tags
  • lists & dropdown tags
  • login/logout tags
  • post tags
  • comment tags
  • date and time tags
  • category tags
  • author tags
  • tag tags
  • edit link tags
  • permalink tags (a URL at which a resource or article will be permanently stored)
  • links manager tags
  • trackback tags
  • general tags
  • geo tags

The the_content() template tag displays the content of the post. The post meta data is the “administrative” information provided to viewers about each post. An archive is a collection of historical posts. In the default usage, the posts displayed on the main index are recent chronological postings. By default, the archive will use index.php, and thus look the same as the front page. A special archive.php file can be used to visually disambiguate archives from the front page. The same is true for category views. It is even possible to create separate category template files for each category.

To cut down the size of a page,  excerpts (a condensed description of a blog post) rather than the entire content of a post or the <!–more–> tag can be used. With the static front page it’s possible to display something special only on the front page of the blog. The list of the typical WordPress pages are listed herafter :

  • home page
  • single post
  • page
  • category
  • tage
  • author
  • date
  • search result
  • 404 (not found)
  • attachment

To style a blog for print, it’s best to use a print.css sytle sheet file. To integrate code in a wordpress page, refer to the following guidelines. Here is a checklist to verify the proper setup of a new theme. Informations about WordPress widgets are available at the widgets website.

The WordPress default theme based on Kubrick contains two stylesheets. The file rtl.css is called when you are using a language localization that reads from right to left (e.g., Arabic or Hebrew). The file style.css is separated in segments:

  • Typography & Colors
  • Structure
  • Headers
  • Images
  • Lists
  • Form Elements
  • Comments
  • Sidebar
  • Calendar
  • Various Tags & Classes
  • Captions

The most recent default Worpdpress theme is Twenty Eleven, version 1.3.

HTML Character Entity References

Character Entities References are the way you put special letters, numbers and symbols on the web page. A character entity reference consists of an ampersand (&), followed by a pound sign (#), the number of the character entity, and finishing with a semi-colon (;). Alternately, for some characters you can put ampersand, the name of the character (but no # sign), followed by a semi-colon.

The following table shows some popular symbols :

34 quot quotation mark = APL quote
38 amp & ampersand
60 lt < less-than sign
62 gt > greater-than sign
160 nbsp no-break space = non-breaking space
169 copy © copyright sign
174 reg ® registered sign = registered trade mark sign
8226 bull bullet = black small circle
bullet is NOT the same as bullet operator

Character entities or extended characters for WordPress are explained on the codex.wordpress.org website.