Re: Script to Populate <title> and <alt>
Use this one instead:
[code:1e02h6o8]
<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
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++ )
document.getElementsByTagName(elArr[i])[0].firstChild.nodeValue=this.getTitle();
for (var c = 0 ; c <imgs.length; c++)
imgs[c].setAttribute('alt',this.clean(imgs[c].src));
},
getTitle:function () {
return document.getElementsByTagName('title')[0].firstChild.nodeValue;
},
clean:function (img) {
var imgs = img.split('/');
return imgs[imgs.length-1].replace(/\.([a-z]){3}/gi,'').replace(/_/g,' ');
}
}
</script>
[/code:1e02h6o8]