-1

我正在使用此代码来提醒页面中的所有元标记。例如http://shodhganga.inflibnet.ac.in/handle/10603/2769在这么多的元数组中使用我想提取另一个页面上的所有元标记。请帮助我。提前致谢

  window.onload = function(){
    var metaData = document.getElementsByTagName('meta')

for(var i=0;i<metaData.length;i++)
{
alert(metaData[i].name);
alert(metaData[i].content);

// talk to your db here for individual entries of meta using name and content
// properties

}
}
4

2 回答 2

1

您正在尝试访问远程页面中的元标记。您需要为此使用 PHP,因为 Javascript 将无法访问该页面中的详细信息。

幸运的是,有get_meta_tags功能。您可以执行以下操作:

$url = 'http://shodhganga.inflibnet.ac.in/handle/10603/2769';
$tags = get_meta_tags($url);
print_r($tags);

例子:

echo $tags['generator'].'<br>';
echo $tags['dcterms_spatial'].'<br>';
echo $tags['dc_creator'];

输出:

DSpace 1.8.2
Physical education
Balasubramanian, K

然后,您可以将这些值传递给 Javascript 并随心所欲地使用它。

希望这可以帮助!

于 2013-08-03T05:13:20.370 回答
-2

在 php 中有 get_meta_tags。使用它,您可以获得所有元标记及其属性。

$tags = get_meta_tags('page_url');
echo $tags['author'];      
echo $tags['keywords'];     
echo $tags['description'];  
echo $tags['geo_position'];
于 2013-08-03T05:15:00.090 回答