JavaScript で title と meta description の値を取得する

published: 2018.03.26 / modified:

JavaScript で、 title 要素の内容や、 meta description の値(<meta name="description"> の content 属性の値)を取得する。

title

document.title プロパティで、 title 要素内のテキスト(タイトル)を取得する。

var title = document.title;

meta description

getElementsByName() メソッドを使用して、 meta description の値(<meta name="description"> の content 属性の値)を取得する。

var description = document.getElementsByName('description')[0].content;

Previous Article

Next Article