Can I stop the meta update using javascript?

The following code allows the user to stop updating metadata - and he successfully deletes it meta refreshfrom 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>

EDIT: this is different from this question because this question requires a backup solution for users who do not support javascript - this does not apply to me (most answers to this question do not apply to this question).

+4
source share
4 answers

Just for completeness, not for my recommended method. You may call:

window.stop();

. Internet Explorer , :

document.execCommand("Stop");
+5

, , , , . , , HTTP-, . onload body, , .

<script type="text/javascript">
$(function(){
  var timer;

  $('body').on('load', function() {
      timer = setTimeout(refresh, 5000);
  });

  $("a").click(function(e){
    e.preventDefault();
    if (timer) {
       clearTimeout(timer);
       timer = null;
    }
  });

  function refresh() {
      timer = null;
      document.location.reload(true);
  }
});
</script>
+4

javascript, . 5 .

javascript :

<!doctype html>
<html>
<head>
<title>Test</title>
<meta charset="UTF-8" />
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
var timer = setTimeout(function() {
  window.location = window.location;
}, 5000);
$(function(){
  $("a").click(function(e){
    e.preventDefault();
    clearTimeout(timer);
  });
});
</script>
</head>
<body>

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

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


</body>
</html>
+1
source

It worked great for me! (tested in chrome)

<button onclick="pauseshow()"><img id="myImg" src="images/pause.jpg" width="45" height="45" style="position:absolute; top:10px; left:1200px;" ></button>
function pauseshow()
{
    window.stop();
    //  Below did not work --> 
    //  var mr = document.getElementById("mymetatag");
    //  mr.parentNode.removeChild(mr);

}
+1
source

All Articles