- Code: Select all
<script type="text/javascript">
/**
Script Created as part of forum request: http://www.devppl.com/forum/script-to-populate-title-and-alt-vt13075.html
Created by Raymond Angana a.k.a rangana in devppl.com/forum
Date Created: 3/17/09
Modification:
* 3/18/09 - Get heading tags and set it to the title
* 3/18/09 - Capitalize every word right after the whiste-space
This notice must stay intact for legal use
*/
window.addEventListener?window.addEventListener('load',function () {
ray.customScript('h1','h2','h3'); // Finds first instance of these tags and change's the nodes to that of the title
},false):
window.attachEvent('onload',function () {
ray.customScript('h1','h2','h3'); // Finds first instance of these tags and change's the nodes to that of the title
}); // FF : IE
var ray = {
customScript:function () {
var elArr = this.customScript.arguments;
var imgs = document.getElementsByTagName('img');
for ( var i = 0 ; i < elArr.length; i++ )
if (document.getElementsByTagName(elArr[i])[0])
this.setTitle(document.getElementsByTagName(elArr[i])[0].firstChild.nodeValue);
for (var c = 0 ; c <imgs.length; c++)
imgs[c].setAttribute('alt',this.clean(imgs[c].src));
},
setTitle:function (val) {
document.title=val;
},
clean:function (img) {
var imgs = img.split('/');
return imgs[imgs.length-1].replace(/\.([a-z]){3}/gi,'').replace(/_/g,' ').replace(/\b[a-z]/g,this.cnvrt);
},
cnvrt:function() {
return arguments[0].toUpperCase();
}
}
</script>
Hope that helps.



