Jump to content

Find meta variable with javascript


Leon
 Share

Recommended Posts

  • Administrators

I was doing a bit of work on my blog that is hosted on a OSX server, when i came to the point that needed to import a meta variable in javascript.. so i made this little function...

 

<script>
function getMeta(varname) {
var metas = document.getElementsByTagName('META');
var i;
for (i = 0; i < metas.length; i++)
if (metas[i].getAttribute('NAME') == varname)
break;
var GMresult = metas[i].getAttribute('CONTENT');
return GMresult;
}
</script>

 

You can test it by doing:

 

<script>
var result = getMeta("Content-Type");
alert(result);
</script>

 

... It should popup a javascript alert with the content of Content-Type

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...