我可以使用javascript停止元刷新吗? [英] Can I stop a meta refresh using javascript?

查看:69
本文介绍了我可以使用javascript停止元刷新吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码允许用户停止元刷新发生 - 并且它成功地从页面中删除了元刷新,但浏览器仍然刷新了页面。知道如何使它工作吗?

The following code allows the user to stop the meta refresh from happening - and it successfully removes the meta refresh from the page, but the browser nonetheless refreshes the page. Any idea how to make it work?

<!doctype html>
<html>
<head>
<title>Test</title>
<meta charset="UTF-8" />
<meta http-equiv="refresh" content="5" id="refresh" />
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
$(function(){
  $("a").click(function(e){
    e.preventDefault();
    $("#refresh").remove();
  });
});
</script>
</head>
<body>

Reloaded at <span id="time"></span>
<script>
document.getElementById("time").innerHTML = Date();
</script> 

<a href="#">Stop refresh</a>


</body>
</html>

编辑:这与这个问题,因为该问题想要一个不支持javascript的用户的后备解决方案 - 对我来说情况并非如此(大多数情况下)这个问题的答案不适用于这个问题。)

this is different from this question because that question wants a fallback solution for users not supporting javascript - this is not the case for me (most of the answers to that question do not apply to this question).

推荐答案

只是为了完整而不是我推荐的方式。你可以打电话:

Just for completeness and not my recommended way. You could call:

window.stop();

停止加载窗口。 Internet Explorer不支持此操作,您必须这样:

To stop loading the window. Internet Explorer doesn't support this and you have to to this:

document.execCommand("Stop");

这篇关于我可以使用javascript停止元刷新吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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