PDA

View Full Version : access meta data using javascript


mdo4
01-30-2003, 03:18 PM
Hello All:

Is there a way, or is there a property of document that can access something like:

<meta name="SECTION" content="About Us">

I want to use these tags to create unique names for each section of a website for a dynamic nav I've written. Also if this is possible, how well does it work on browsers as old, but not older than say NS4? Thanks in advance.

-Mike

kdjoergensen
01-30-2003, 05:18 PM
No you can not do that.

however you can use javascript variables, or even hidden input tags in html forms.

example:

<script>
var thisPage = "flower";
var keywords = "rose,fertilizing,care"
var author = "myself"
</script>

or
<form name="pageInfo">
<input type="hidden" name="author" value="myself">
<input type="hidden" name="title" value="fertilizing roses">
<input type="hidden" name="chapter" value="roses">
</form>

document.write("<B>"+document.pageInfo.chapter.value+"</B>");

good luck

mdo4
01-30-2003, 05:27 PM
Kenneth,

Thanks for the answer. I did come across this...

<meta name="test" content="myValue">

...
<script>
var metaArray = document.getElementsById("test");
alert(metaArray[0].content);
</script>

This would prompt out myValue.

The only fall back to this is it's only accessable via getElementsByID, document.ids won't pick it up, therefore non-W3C compliant browsers are out of luck. So I did go the hidden field route.

-Mike