Forum Moderators: open
javascript: alert(document.getElementsByTagName("meta")[0].content)
But what I'm after is a particular one, not the first in an arbitrary order. Suppose I wanted the text corresponding to the keywords, is there a simple way of modifying the array index above to get that? Or maybe an even simpler one? indexOf( doesn't seem to work. I guess I'm overlooking something...
Any help would be much appreciated. Thanks in advance.
Hi,try:
function getMetaContents(mn){ ...
Not quite what was asked for. If you need the value of a specific meta element's 'content' attribute, the only way to do it is for you to give your script some kind of parameters to look for. You probably need something like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>metaKeywords() test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="foo" content="bar" />
<meta name="keywords" content="bar, foo, fubar" />
<script type="text/javascript">
function metaKeywords() {
metaCollection = document.getElementsByTagName('meta');
for (i=0;i<metaCollection.length;i++) {
nameAttribute = metaCollection[i].name.search(/keywords/);if (nameAttribute!= -1) {
alert(metaCollection[i].content);
}
}
}
</script>
</head><body onload="metaKeywords();">
<p>Test</p>
</body>
</html>
Sorry for the total lack of indents :-¦
-b
If anybody is interested, the code is as follows:
javascript: t=document.getElementsByTagName(%22meta%22); s=%22%22; for(i=0;i<t.length;i++){if(t[i].name==%22ICBM%22 ¦¦ t[i].name==%22geo.position%22) s=t[i].content;}; if(s==%22%22) alert("No data available"); else window.open(%22http://maps.google.co.uk/?q=%22+s)
It makes for a good bookmar that can then be called whenever you want. I guess it could be adapted to use your other favorite mapping engine (Yahoo, Mapquest, etc)