Using JavaScript to Override or Disable Meta Refresh Tag

Remove meta tag refresh

Removing the meta tag isn't an option, based on the link Robert Rozas added --> Using Javascript to override or disable meta refresh tag

Since I don't have your code I can't help completely, but below is a way to auto refresh the page on load & then stop refreshing it on an event.

Clicking on the Test Button will stop the refresh.. just hook this into your event and it should solve your problem -->

 <script>
$(document).ready(function () {
$("#test").click(function (e) {
// This event will clear the timeout
clearTimeout(timeout);
});

var timeout = setTimeout(function()
{
// The refresh is occurring here
location.reload();
}, 4000);

});
</script>
<button id="test">Test</button>

The following will remove the meta tag (quotes removed)

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

Is it possible to disable meta refresh in Google Chrome?

I was looking for the same kind of extension (Spanish online newspapers abuse of the meta/refresh tag), I found none, and, among other sites, I landed in this question.

So I started to analyze how this could be done. It was not simple, and needed some tricks, but I've done it.

The extension is already in Chrome Web Store, "Stop Autorefresh": https://chrome.google.com/webstore/detail/lcldcllmbokpbniijpnkpgoboadbfphb

More info, mostly in Spanish, in http://gallir.wordpress.com/2012/07/12/stop-autorefresh-evitar-la-recarga-automatica-tipica-de-los-periodicos-digitales-en-chromechromium/

From the extension description:

Implementation notes: Chrome and Chromium don't allow to disable the refresh meta tag, nor they provide an easy method for cancelling it. The extension uses a http trick. When the [unavoidable] refresh is fired, it intercepts it, checks if it's the refresh event, if so, it redirects the connection to a small script (currently en App Engine). This script just returns a 204 http status code, so the browser does not modify the content of the page, and doesn't try to refresh it again.

Meta refresh tag not redirecting with noscript tags

The error cause by the quote. Try change it to:

<?php
echo "<noscript>
<meta http-equiv='refresh' content='0; url=http://mysite.tld/javascript-disabled.html' />
</noscript>";
?>

But i'm dought if this will work.

A diffrent approach will be to create a non-javascript page and use javascript to redirect. Something like:

window.location.assign("jsenable.html")

Good luck!

Disable HTML auto-refresh?

Assuming you are using a UIWebView to display the site, you could use [webView stringByEvaluatingJavaScriptFromString:@"..."];, where "..." is this javascript:

    var metaTags = document.getElementsByTagName("META");
for(var i = 0; i < metaTags.length; i++) {
if (metaTags[i].getAttribute("HTTP-EQUIV").match(/^REFRESH$/i))
metaTags[i].parentNode.removeChild(metaTags[i]);
}

Condensed down to one line for convenience:

var metaTags = document.getElementsByTagName("META"); for(var i = 0; i < metaTags.length; i++) { if (metaTags[i].getAttribute("HTTP-EQUIV").match(/^REFRESH$/i)) { metaTags[i].parentNode.removeChild(metaTags[i]);}}

Edit: Well...after all that, turns out it's not possible to cancel an existing refresh request by simply removing the meta tag from the document. Once the parser sees the meta tag, it will refresh regardless of any javascript trickery you do. Unfortunately, the only way to overcome this is to modify the HTML page directly.

meta refresh redirect to top frame

Javascript won't work in the refresh meta tag like that.

As you're using javascript anyway, keep it simple like this:

<script type="text/javascript">
window.top.location = 'http://domain.tld/whatever/';
</script>

But there's also a better (because smarter) way to do it. This doesn't require you to hard-code the URL for each page. It checks if the page is topmost and if not, if calls the page's URL to the top:

<script type="text/javascript">
if(window.top.location != window.location)
{
window.top.location.href = window.location.href;
}
</script>

And if you would prefer to completely avoid using javascript (which some users will have disabled), there's also an even simpler way to do it. Add the following to your head section and all links on that page will open "topmost":

<base target="_top">

All you have to do is to choose one of these three options. All of them should get you going just fine.



Related Topics



Leave a reply



Submit