meta 刷新_META刷新与JavaScript刷新

本文探讨了在ESPN.com源代码中发现的JavaScript和META刷新的用法。虽然JavaScript通常作为主要刷新方法,但W3C不推荐使用META刷新,因为它可能导致用户迷失方向并影响某些浏览器的返回功能。现代浏览器已对此进行补偿,但在自动页面刷新时,建议使用JavaScript为主,META为备选方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

meta 刷新

A few days back I was perusing the ESPN.com source code when I found the following snippet of code:

几天前,当我发现以下代码片段时,我正在细读ESPN.com源代码:


<script>
	ESPN_refresh=window.setTimeout(function(){window.location.href=window.location.href},900000);
</script>
<noscript>
	<meta http-equiv="refresh" content="900" />
</noscript>


I understand what the code was supposed to do but was confused as to why they'd use JavaScript as a primary method and META as a fallback method. Why not just use the META method? I did some research and found the answer at Wikipedia:

我了解代码应该执行的操作,但是对于为什么将JavaScript作为主要方法而将META作为后备方法的原因感到困惑。 为什么不只使用META方法呢? 我做了一些研究,并在Wikipedia上找到了答案:

Use of meta refresh is discouraged by the W3C, since unexpected refresh can disorient users. Meta refresh also impairs the web browser's "back" button in some browsers (including Internet Explorer 6 and before), although most modern browsers compensate for this (Mozilla Firefox, Opera, Internet Explorer 7).

W3C不鼓励使用元刷新,因为意外刷新可能会使用户迷惑。 元数据刷新还会损害某些浏览器(包括Internet Explorer 6和更低版本)中Web浏览器的“后退”按钮,尽管大多数现代浏览器都对此进行了补偿(Mozilla Firefox,Opera,Internet Explorer 7)。

So there you have it. Use JavaScript as your primary means for automatic page refreshes and a META tag as your fallback.

所以你有它。 使用JavaScript作为自动刷新页面的主要方法,并使用META标签作为后备。

翻译自: https://davidwalsh.name/meta-refresh-javascript

meta 刷新

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值