如何在javascript中添加元标记 [英] How to add meta tag in javascript

查看:108
本文介绍了如何在javascript中添加元标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为特定网页添加< meta http-equiv =X-UA-Compatiblecontent =IE = edge>

但我的页面是在一个 HTML 标签内呈现的。只有在单击不同模板时内容才会发生变化。所以我无法在< HEAD> 部分添加< meta>

But my pages are rendered inside one HTML tag. Only the content is changing on clicking different templates. So i cannot add the <meta> in <HEAD> section.

有没有办法添加< meta http-equiv =X-UA-Compatiblecontent =IE = edge> 使用 javascript

Is there any way to add the <meta http-equiv="X-UA-Compatible" content="IE=edge"> using javascript ?

推荐答案

您可以添加它:

var meta = document.createElement('meta');
meta.httpEquiv = "X-UA-Compatible";
meta.content = "IE=edge";
document.getElementsByTagName('head')[0].appendChild(meta);

...但是如果到了跑的时候我已经不会感到惊讶了做出了关于如何呈现页面的决定。

...but I wouldn't be surprised if by the time that ran, the browser had already made its decisions about how to render the page.

这里的真正答案必须是首先从服务器输出正确的标签,或者(当然)不要回复X-UA兼容。

The real answer here has to be to output the correct tag from the server in the first place, or (of course) not to reply on X-UA-Compatible at all.

这篇关于如何在javascript中添加元标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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