是否可以使用 jQuery 从标头动态删除元刷新标记?
我在标题中有这样的元标记..
<meta http-equiv='refresh' content='0;url=http://stackoverflow.com/'>
是否可以使用 jQuery 动态删除它?
I have meta tag in Header like that..
<meta http-equiv='refresh' content='0;url=http://stackoverflow.com/'>
is it possible to Remove it Dynamically using jQuery ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
为了在启用脚本支持时实现不同的行为,您应该在
标记之间包含元刷新,如下所示,
并在加载 DOM 后实现所需的功能。大致内容如下:
已确认正在使用最新的 Firefox 版本
In order to implement different behavior when scripting support is enabled you should include the meta refresh between
<noscript>
tags, like soand implement the desired functionality after loading the DOM. Something along the lines of:
Confirmed working on the latest Firefox version
不。
首先,加载 jQuery 库会花费太长时间,因此您必须直接使用 Javascript(如果有的话)来完成。
其次,即使元有一个 id 并且您将最简单的 JS 片段紧随其后:
仍然为时已晚,因为元中的
content=0
意味着立即执行刷新,因此脚本永远不会被执行。如果将脚本放在元之前,它将无法工作,因为还没有 DOM 元素可供引用。No.
First, loading the jQuery library would take way too long so you'd have to do it with straight Javascript if anything.
Second, even if the meta had an id and you placed the simplest JS snippet immediately after it:
it would still be too late because the
content=0
in the meta means to execute the refresh immediately so the script will never be executed. If you placed the script before the meta it wouldn't work because there would be no DOM element yet to reference.据我所知,这没有任何意义。您显示的标头应该会导致立即重定向,可能在任何 JavaScript 执行之前。
如果你可以使用 jQuery 来更新它,你不妨这样做:
我不知道这将如何在存在 Meta 标签的情况下执行 - 它是否总是击败 Meta 标签,总是输给它,或者导致不一致跨浏览器的结果。
也许可以告诉我们您的具体情况以及为什么需要这样做。
As far as I can see, this doesn't make any sense. The header you show is supposed to cause an immediate redirect, possibly before any JavaScript ever gets executed.
If you can use jQuery to update it, you might as well do this:
I don't know how this will be executed with the Meta tag present though - whether it will always beat the Meta tag, always lose against it, or cause inconsistent results across browsers.
Maybe tell us what exactly your situation is and why you need to do this.
试试这个:
Try this:
对我有用的不是删除它,而是将值更改为一个非常大的数字,然后它永远不会刷新,如下所示:
What worked for me is not to remove it, but to change the value to a very big number, then it will never refresh as below: