是否可以使用JavaScript来更改页面的元标记? [英] Is it possible to use JavaScript to change the meta-tags of the page?

查看:142
本文介绍了是否可以使用JavaScript来更改页面的元标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在头部放一个div并显示:none,而不是使用JavaScript来显示它,这会有效吗?

If I put a div in the head and display:none, than use JavaScript to display it, will this work?

编辑:

我在AJAX中加载了东西。当我的AJAX更改网站的主要部分时,我也想更改元标记。

I have stuff loaded in AJAX. And as my AJAX changes the "main" portion of the site, I want to change the meta-tags as well.

推荐答案

是的,你可以这样做。

有一些有趣的用例:一些浏览器和插件解析元元素并改变它们对不同值的行为。

There are some interesting use cases: Some browsers and plugins parse meta elements and change their behavior for different values.

<meta name="SKYPE_TOOLBAR" content="SKYPE_TOOLBAR_PARSER_COMPATIBLE">



iPhone:关闭电话号码解析器



iPhone: Switch off phone number parser

<meta name="format-detection" content="telephone=no">



Google Chrome浏览器内嵌框架



Google Chrome Frame

<meta http-equiv="X-UA-Compatible" content="chrome=1">



移动设备的视口定义



Viewport definition for mobile devices

<meta name="viewport" content="width=device-width, initial-scale=1.0">

这个可以通过JavaScript更改。请参阅:修复iPhone视口缩放错误

This one can be changed by JavaScript. See: A fix for iPhone viewport scale bug

某些用户代理(例如Opera)使用书签描述。您可以在此处添加个性化内容。示例:

Some user agents (Opera for example) use the description for bookmarks. You can add personalized content here. Example:

<!DOCTYPE html>
<title>Test</title>
<meta name="description" content="this is old">
<script type='text/javascript' src='http://code.jquery.com/jquery-1.8.2.js'></script>

<button>Change description</button>

<script type='text/javascript'>
$('button').on('click', function() {
    // Just replacing the value of the 'content' attribute will not work.
    $('meta[name=description]').remove();
    $('head').append( '<meta name="description" content="this is new">' );
});
</script>

所以,它不只是关于搜索引擎。

So, it’s not just about search engines.

这篇关于是否可以使用JavaScript来更改页面的元标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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