by sagreiss on Mon Mar 16, 2009 5:22 pm
This lovely little line of code works, but the "newTitle" element needs to be inserted manually, which sucks.
<body onload='javascript: document.title = document.getElementById("newTitle").innerHTML;'>
Someone has suggested amending it with the following, but the code is not written in inline format, and some of the syntax is not quite the same, so I can't make it work, and it doesn't provide for the absence of an instance of h1, i.e. proceed to h2, then h3:
function updateTitle() {
var title = document.getElementsByTagName("H1")[0];
if (title) document.title = title.innerHTML;
}
This script works reasonably well for the <alt> image tags:
<script>
function writealt()
{
for (pic = 0; pic<document.images.length; pic++)
{
document.images[pic].alt = document.images[pic].src
}
}
</script>
</head>
<body onload="writealt();">
For some reason it seems to be picking up path with filename. I've tried everything I can think of, adding to or replacing src with various elements such as file, filename etc. Nothing seems to work.
Eliminating extension, replacing underscore by a space character, and converting to title case would be perfect.
I apologize if these questions are dumb, but I am not a programmer.