javascript - Disable HTML auto-refresh? - Stack Overflow

A client's website has an auto-refresh feature which works great for desktop sites, but I'm m

A client's website has an auto-refresh feature which works great for desktop sites, but I'm making an iPhone app and need to disable it on the mobile version.

The code used is:

<META HTTP-EQUIV="REFRESH" CONTENT="30">

I would like to use javascript to disable it, if possible.

Thanks.

EDIT: I DO NOT have access to the HTML file, and therefore can't modify it. I need to do this via code on the Objective-C side in Xcode.

A client's website has an auto-refresh feature which works great for desktop sites, but I'm making an iPhone app and need to disable it on the mobile version.

The code used is:

<META HTTP-EQUIV="REFRESH" CONTENT="30">

I would like to use javascript to disable it, if possible.

Thanks.

EDIT: I DO NOT have access to the HTML file, and therefore can't modify it. I need to do this via code on the Objective-C side in Xcode.

Share Improve this question edited Oct 15, 2015 at 18:26 Captain Obvlious 20.1k5 gold badges48 silver badges80 bronze badges asked Oct 19, 2011 at 21:17 iOSDeviOSDev 1,0284 gold badges13 silver badges21 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 1

I will introduce something simple

Add meta tag with ID id="meta-refresh" like this:

 <meta http-equiv="refresh" content="2;http://new-url/" id="meta-refresh">

Just use these script..

 var iOS = false,
     p = navigator.platform;
 if( p === 'iPad' || p === 'iPhone' || p === 'iPod' ){//remove which is not your target
     iOS = true;
 }
 if(iOS){ // check if iOS then do the following
      var mr = document.getElementById("meta-refresh");
      mr.parentNode.removeChild(mr);
 }

I believe this will work..

Also, the initiated request which JavaScript can not disable once loaded!! For the same, the exact work around one can find in an Old Post answer given by user XP1

The above is using xmlhttp requrest (AJAX) to check before the document is loaded and remove the meta tag if the device is target device(iphone)

OR

one can use refresh dynamically id the device is not iPhone/iOS. that will remove the requirement of doing the dynamic check and requirement to avoid first refresh call. without using meta tag

 var iOS = false,
     p = navigator.platform;
 if( p === 'iPad' || p === 'iPhone' || p === 'iPod' ){//remove which is not your target
     iOS = true;
 }
 if(!iOS){
      window.setTimeout(function(){window.location.href=window.location.href},30000); //30 Seconds
 }

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 overe this is to modify the HTML page directly.

short answer: window.location.reload = () => {}

longer answer: most browsers support some modification of a function that refreshes a web page. the one here was tested on Chrome.

Disclaimer: this will remove the page reloading functionality entirely for a given page.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745355797a4624108.html

相关推荐

  • javascript - Disable HTML auto-refresh? - Stack Overflow

    A client's website has an auto-refresh feature which works great for desktop sites, but I'm m

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信