通过jQuery从URL获取元标记 [英] Fetch meta-tags from url only by jQuery

查看:205
本文介绍了通过jQuery从URL获取元标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在很多脚本以Facebook的形式从url获取数据,但是它们都只能结合使用jQuery和PHP。是否可以通过jQuery获取网址?

Now a lot of scripts to facebook-style fetching data from url, but all of them work only in combination of jQuery and PHP. Is it possible to fetch url only by jQuery?

我在这里找到如何通过以下方式获取页面的mata标签:

I have found here how to get mata-tags of page by:

$('meta[name=description]').attr("content");
$("meta[property=og:title]").attr("content", document.title);

但是如何在jQuery.get()中插入此查询以获取文本值?

But how correctly insert this query in jQuery.get() to get text values?

$.get('http://www.imdb.com/title/tt1375666/', function(data) {
  $('meta[name=adescription]').attr("content");
});

如果最受欢迎的网站使用OpenGraph,我应该查看jQuery.getJSON()的方向吗?

And if the most popular sites use OpenGraph should I look in the direction of jQuery.getJSON()?

推荐答案

使用从URL检索的html数据

Use the html data retrieved from URL

$.get('http://www.guardian.co.uk/culture/2012/jun/21/jimmy-carr-apologises-error-tax', 
function(data) {
   $(data).find('meta[name=adescription]').attr("content");
});

这篇关于通过jQuery从URL获取元标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆