Hi Everyone - Your help would be greatly appreciated
I have the following code: It is suppose to get the metatags from a website:
function calculate() {
// This gets the title:
g_title = ('' + document.title + '');
g_title_count = ('' + document.title.split(' ').length + '');
g_title_length = ('' + document.title.length + '')
// This checks all the MetaTags:
g_metadata = document.getElementsByTagName("meta")[i];
g_keywords = "test";
if (typeof g_metadata != 'undefined') {
if (g_metadata) {
var i = 0;
for (i = 0; i <= 10; i++) {
if (g_metadata.name == 'keywords') {
g_keywords[i] = (g_metadata.name[i] + g_metadata.content[i]);
}
}
}
}
}
This value currently returns "test" as specified in the code above:
document.form1.g_keywords.value = g_keywords
However I need it to capture the keywords metatag, description and title.
<title>Test 1</title>
<meta name="keywords"content="test2" />
<meta name="description" content="test3" />
and then write it to a form:
<textarea name="g_keywords" id="g_keywords" cols="80" rows="5" onchange="calculate(this.form1)"></textarea>
It currently works for the Title
but not to get the <meta name="keywords" content="" >
tag
if (g_metadata.name == 'keywords') {
g_keywords[i] = (g_metadata.name[i] + g_metadata.content[i]);
}
I have tried it by creating the above but are not sure how to execute it...
Please help - Thanks