Javascript以动态更改元数据/元标签 [英] Javascript To Change Metadata / Metatags Dynamically

查看:160
本文介绍了Javascript以动态更改元数据/元标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会描述我想要完成的任务,如果看起来我的方法是愚蠢的,请随时让我知道:



我有一个页面与视频库和Flash视频播放器iframe。当用户点击视频缩略图时,它将开始在框架中播放。



用户还可以通过将iframe中的特定视频加载到页面,文件路径到url-blabla.com/videogallery?videofilepath的末尾。我设置了这个,以便视频可以很容易地共享。



我想要添加分享按钮为Facebook / twitter,但我不能让他们工作和礼物自己正确使用正确的元数据(图像和标题)。



所以我正在考虑将Share按钮放在播放器iframe中,然后动态更新元数据标签发生视频更改,但不确定如何进行此操作。



感谢您的帮助将不胜感激。

解决方案

你想在jQuery代码中做这样的事情

  $(document).ready(function(){
$('title')。text(你的新标题在这里);
$('meta [name = description]') ('content','new Meta Description here');
});


I'll describe what I'm trying to accomplish and if it seems that my method is dumb please feel free to let me know:

I have a page with a video gallery and a flash video player iframe. When the user clicks on a video thumbnail, it starts to play in the frame.

Users can also go to the page with a specific video loaded into the iframe by appending the filepath to the end of the url - blabla.com/videogallery?videofilepath. I set this up so that videos could be shared easily.

I want to be able to add Share buttons for facebook/twitter, but I cannot get them to work and present themselves properly with the correct metadata (image and title).

So I was thinking of putting the Share buttons in the player iframe as well and then update the metadata tags dynamically when a video change occurs, but am unsure as to how to go about this.

Any help would be much appreciated, thanks.

解决方案

You wanna do something like this in the code for jQuery

$(document).ready(function(){
    $('title').text("Your new title tag here");
    $('meta[name=description]').attr('content', 'new Meta Description here');
});

这篇关于Javascript以动态更改元数据/元标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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