我可以使用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");