Is it possible to dynamically remove the meta refresh tag from the header using jQuery?

I have a meta tag in a header like this.

<meta http-equiv='refresh' content='0;url=http://stackoverflow.com/'> 

Is it possible to dynamically delete it using jQuery?

+6
source share
5 answers

As far as I understand, this makes no sense. The header you are showing is supposed to cause an immediate redirect, possibly before any JavaScript is executed.

If you can use jQuery to update it, you can also do this:

 location.href = "http://new.target"; 

I don’t know how this will be accomplished with the meta tag present - whether it will always beat the meta tag, always play against it or cause inconsistent results in browsers.

Perhaps tell us what exactly your situation is and why you need to do this.

+2
source

To implement various behaviors while supporting scripting support, you must enable meta-refresh between <noscript> tags, for example

 <noscript> <meta http-equiv='refresh' content='0;url=http://stackoverflow.com/'> </noscript> 

and implement the required functionality after loading the DOM. Sort of:

 $(window).load(function() { // here }) 

Confirmed work on the latest version of Firefox

+6
source

Not.

Firstly, loading the jQuery library will take too long, so you have to do it using direct Javascript.

Secondly, even if the meta had an identifier, and you immediately sent the simplest fragment of JS:

 <meta id="stopMe" http-equiv='refresh' content='0;url=http://stackoverflow.com/'> <script> var meta = document.getElementById('stopMe'); meta.parentNode.removeChild(meta); </script> 

it will still be too late, because content=0 in meta means the update is immediately executed, so the script will never be executed. If you put the script in front of the meta, this would not work, because there was no DOM element for the link.

+5
source

What worked for me was not to delete it, but to change the value to a very large number, then it will never be updated, as shown below:

 $('meta').prop('content', '99999999'); 
-1
source

Try the following:

 $('meta[http-equiv="refresh"]').remove(); 
-2
source

Source: https://habr.com/ru/post/897449/


All Articles