PDA

View Full Version : Display document author


Marc S
03-14-2003, 03:42 PM
Is is possible to display the author (creator/modifier) of a web page through Javascript?

We have an Intranet site with various departmental authors contributing web pages. It would be great to display the author of a page. FYI, each author uses secure FTP to upload their pages to the Intranet server (using Dreamweaver MX FTP) but I just don't know how to grab this data.

beetle
03-14-2003, 04:25 PM
If they use 'author' meta tags<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Meta test</title>
<meta name="keywords" content="blah" />
<meta name="description" content="blah" />
<meta name="Author" content="Peter Bailey" />
<meta name="Generator" content="TextPad 4.4" />

<script type="text/javascript">

function init()
{
showAuthor( '_author' );
}


function showAuthor( oId )
{
var metas = document.getElementsByTagName( "meta" );
for ( var meta, i = 0; ( meta = metas[i] ); i++ )
{
if ( meta.name.toUpperCase() == 'AUTHOR' )
{
document.getElementById( oId ).appendChild( document.createTextNode( meta.content ) );
return;
}
}
}

</script>
</head>

<body onload="init();">

<div id="_author"></div>

</body>
</html>
I had to use "_author" for the ID, because IE got confused and grabbed the 'author' meta-tag iteslf :rolleyes:

You, of course, can name it anything you like, just not "author"