更改元刷新的内容不会改变刷新时间 [英] Changing the content of meta refresh does not change refreshing time

查看:230
本文介绍了更改元刷新的内容不会改变刷新时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< head> 中有一个 meta http-equiv =refresh

<head>
     <meta name="mymeta" http-equiv="refresh" content="2" id="myMeta">
</head>

使用 Javascript ,我试图改变<$ c $这个 meta 标记的c> content 属性。

Using Javascript, I'm trying to change the content attribute of this meta tag.

var myMeta = document.getElementById("myMeta");
myMeta.content="10";

当我通过 document.write(myMeta.content)显示内容时; ,我得到的值是 10 ,但是, meta 标签会每次刷新 2

When I display the content via document.write(myMeta.content);, I get the changed value which is 10, however, the meta tag will keep refreshing each 2 seconds.

我已经在Firefox和Opera中测试了这个功能。

I have tested this both in Firefox and Opera.

FULL PAGE

<!DOCTYPE html>
<html>
<head>
<meta name="mymeta" http-equiv="refresh" content="2" id="myMeta">
<script>
var myMeta=document.getElementById("myMeta");
myMeta.content="10";
document.write(myMeta.content);
</script>
</head>
<body>
</body>
</html>


推荐答案

这是因为浏览器立即处理< meta> 标记。

This happens because the browser immediately process the <meta> tag when it is present onload.

请参阅 DEMO

当文档被加载时,浏览器会看到并处理以下内容:

When the document is being loaded, the browser sees and processes the following:

<meta name="mymeta" http-equiv="refresh" content="2" id="myMeta"/>

尽管您尝试将其内容从2更改为10,但2秒刷新已被确认,浏览器在刷新页面之前等待2秒钟。由JavaScript注入的10秒刷新实际上工作*,尽管页面在2秒内刷新并且没有任何事情发生。然后再重复这个过程。

Even though you try to change its content from 2 to 10, that 2 second refresh is already acknowledged and the browser waits for 2 seconds before it refreshes the page. The 10-second refresh that is injected by JavaScript actually works*, although the page has been refreshed by the time it reaches 2 seconds and nothing seems to happen. This process is then repeated again and again.

试试,看看会发生什么。

Try the opposite and see what happens.

*这只适用于Safari和Chrome。 Firefox和Opera不支持通过JavaScript修改元刷新。

这篇关于更改元刷新的内容不会改变刷新时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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