不幸的是,從@bluesmoon's answer開始,操縱DOM不再有效。
解決方法是檢索原始標記,查找並替換元刷新元素,然後用替換的標記寫入新文檔。
我不知道如何使用JavaScript檢索原始標記,除了使用XMLHttpRequest
發送附加請求。
在Opera中,這裏是我使用的是什麼:
Disable meta refresh 1.00.js
:
// ==UserScript==
// @name Disable meta refresh
// @version 1.00
// @description Disables meta refresh.
// @namespace https://stackoverflow.com/questions/3252743/using-javascript-to-override-or-disable-meta-refresh-tag/13656851#13656851
// @copyright 2012
// @author XP1
// @homepage https://github.com/XP1/
// @license Apache License, Version 2.0; http://www.apache.org/licenses/LICENSE-2.0
// @include http*://example.com/*
// @include http*://*.example.com/*
// ==/UserScript==
/*
* Copyright 2012 XP1
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*jslint browser: true, vars: true, maxerr: 50, indent: 4 */
(function (window, XMLHttpRequest) {
"use strict";
if (window.self !== window.top) {
return;
}
window.stop();
var uri = window.location.href;
var request = new XMLHttpRequest();
request.open("GET", uri, false);
request.send(null);
if (!(request.readyState === 4 && request.status === 200)) {
return;
}
var markup = request.responseText;
markup = markup.replace(/<meta http-equiv="refresh".*\/?>/gi, "");
var document = window.document;
document.open();
document.write(markup);
document.close();
}(this, this.XMLHttpRequest));
歌劇也有一個內置的功能,禁用元刷新。不需要JavaScript。
- 右鍵單擊網頁>編輯站點首選項...>網絡>禁用「啓用自動重定向」>確定。
來源
2012-12-01 05:52:20
XP1
我想我從這個問題中學到,我想要做的是很多麻煩,可能不值得花費精力和處理所有問題。我想我可能會像Hrishi建議的那樣重定向,或者如果我希望Javascript和非Javascript頁面使用相同的URL,那麼我只能在用戶選擇啓用它們時使用元刷新標記,並記住用戶使用cookie的選擇。謝謝你的答案。 – 2010-07-25 04:08:21