JavaScript可以用来加载其他页面的元数据内容? [英] Can JavaScript be used to load another page's metadata content?

查看:154
本文介绍了JavaScript可以用来加载其他页面的元数据内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网站上所有的页面都在作者的< HEAD>

On my website all the pages have an author in the <head>:

<meta name="Author" content="Mark Brown" />

我想创建一个链接页面,一个接一个打电话与jQuery该页面的作者元数据内容的价值。

I want to create a page of links and next to each call that page's Author metadata content value with jQuery.

我想这并没有奏效:

.load( '{URLHERE}' + $('meta[name=Author]').attr('content') )

对不起我是JS新手。我似乎 .load()只获取标记中的内容?是对的吗?任何想法如何,我会这么做吗?

Sorry I'm a JS Newbie. I seems that .load() only gets content inside the body tag? Is that right? Any ideas how I'd do this?

推荐答案

您可以使用负荷活动分为两个阶段:

You can use the load event in two stages:

$("#your-target").load("{URLHERE} meta[name='Author']", function(response, status, xhr){
    var $meta = $("meta", this);

    $(this).text($meta.attr("content"));

    $meta.remove();
});

这将首先加载标签到你的目的地,并使用完整 回调,你可以得到的作者属性的值。

This will first load the meta tag into your destination and by using the complete callback, you can get the value of the Author attribute.

这篇关于JavaScript可以用来加载其他页面的元数据内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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