Thật không may, từ @bluesmoon's answer, thao tác DOM không hoạt động nữa.
Giải pháp thay thế là truy xuất đánh dấu gốc, tìm và thay thế phần tử làm mới meta, sau đó viết tài liệu mới bằng đánh dấu thay thế.
Tôi không chắc chắn cách truy xuất đánh dấu gốc bằng JavaScript ngoại trừ việc gửi yêu cầu bổ sung bằng cách sử dụng XMLHttpRequest
.
Trong Opera, đây là những gì tôi đang sử dụng:
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));
Opera cũng đã tích hợp sẵn trong tính năng vô hiệu hóa hàm nạp lại sau. Không cần JavaScript.
- Nhấp chuột phải vào trang web> Chỉnh sửa tùy chọn trang web ...> Mạng> Tắt "Bật chuyển hướng tự động"> OK.
Tôi nghĩ rằng tôi đã học được từ câu hỏi này rằng những gì tôi đang cố gắng làm là rất nhiều rắc rối và có lẽ không đáng để chi tiêu và giải quyết mọi vấn đề.Tôi nghĩ rằng tôi có thể chuyển hướng như Hrishi đề xuất, hoặc nếu tôi muốn các trang Javascript và không phải Javascript sử dụng cùng một URL, tôi chỉ có thể sử dụng thẻ làm mới meta nếu người dùng chọn bật chúng và nhớ lựa chọn của người dùng bằng cookie. Cảm ơn tất cả các câu trả lời của bạn. –