I have a bookmarklet that gets the meta keywords on a page. However if the there are no meta keywords the bookmarklet breaks.
Here is my current javascript
function docoument_keywords(){
var keywords;
var metas = document.getElementsByTagName('meta');
for (var x=0,y=metas.length; x<y; x++) {
if (metas[x].name.toLowerCase() == "keywords") {
keywords = metas[x];
}
}
return keywords.content;
}
k = document_keywords();
$('body').append("<p>" + k + "</p><p>Content</p>");
The bookmarklet works fine when there are actually keywords in the meta keywords. However its break when there are none. You guys have any solutions?
Much appreciated!
Working example: JS Fiddle