禁用 HTML 自动刷新?

发布于 2024-12-10 20:38:49 字数 272 浏览 2 评论 0原文

客户的网站具有自动刷新功能,该功能非常适合桌面网站,但我正在制作 iPhone 应用程序,需要在移动版本上禁用它。

使用的代码是:

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

如果可能的话,我想使用javascript来禁用它。

谢谢。

编辑: 我无权访问 HTML 文件,因此无法修改它。我需要通过 Xcode 中 Objective-C 端的代码来完成此操作。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

酒中人 2024-12-17 20:38:49

我将介绍一些简单的

添加 ID 为 id="meta-refresh"meta 标记,如下所示:

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

只需使用这些脚本..

 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);
 }

我相信这会起作用..

另外,一旦加载,JavaScript 就无法禁用发起的请求!
同样,可以在 < 中找到确切的解决方法code>Old Post 用户给出的答案 XP1

上面使用 xmlhttp requrest (AJAX) 在文档加载之前进行检查,如果设备是目标,则删除元标记设备(iPhone)

或者

可以使用动态刷新ID该设备不是iPhone/iOS。这将消除进行动态检查的要求以及避免第一次刷新调用的要求。不使用元标记

 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
 }

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
 }
酷到爆炸 2024-12-17 20:38:49

假设您使用 UIWebView 来显示站点,您可以使用 [webView stringByEvaluatingJavaScriptFromString:@"..."];,其中“...”是此 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]);
    }

压缩为一行便利:

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]);}}

编辑:嗯...毕竟,事实证明,通过简单地从文档中删除元标记是不可能取消现有的刷新请求的。一旦解析器看到元标记,无论您执行任何 JavaScript 欺骗,它都会刷新。不幸的是,解决这个问题的唯一方法是直接修改 HTML 页面。

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.

┊风居住的梦幻卍 2024-12-17 20:38:49

简短回答:window.location.reload = () => {}

较长的答案:
大多数浏览器支持对刷新网页的功能进行某些修改。
这里的测试是在 Chrome 上进行的。

免责声明:这将完全删除给定页面的页面重新加载功能。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文