<bdo id='93Bz5'></bdo><ul id='93Bz5'></ul>

    <tfoot id='93Bz5'></tfoot>

    1. <i id='93Bz5'><tr id='93Bz5'><dt id='93Bz5'><q id='93Bz5'><span id='93Bz5'><b id='93Bz5'><form id='93Bz5'><ins id='93Bz5'></ins><ul id='93Bz5'></ul><sub id='93Bz5'></sub></form><legend id='93Bz5'></legend><bdo id='93Bz5'><pre id='93Bz5'><center id='93Bz5'></center></pre></bdo></b><th id='93Bz5'></th></span></q></dt></tr></i><div id='93Bz5'><tfoot id='93Bz5'></tfoot><dl id='93Bz5'><fieldset id='93Bz5'></fieldset></dl></div>

      <small id='93Bz5'></small><noframes id='93Bz5'>

    2. <legend id='93Bz5'><style id='93Bz5'><dir id='93Bz5'><q id='93Bz5'></q></dir></style></legend>

      检索和修改 XMLHttpRequest 的内容

      时间:2023-10-13

        <small id='f1sdF'></small><noframes id='f1sdF'>

      • <tfoot id='f1sdF'></tfoot>
      • <legend id='f1sdF'><style id='f1sdF'><dir id='f1sdF'><q id='f1sdF'></q></dir></style></legend>
            <tbody id='f1sdF'></tbody>

            <i id='f1sdF'><tr id='f1sdF'><dt id='f1sdF'><q id='f1sdF'><span id='f1sdF'><b id='f1sdF'><form id='f1sdF'><ins id='f1sdF'></ins><ul id='f1sdF'></ul><sub id='f1sdF'></sub></form><legend id='f1sdF'></legend><bdo id='f1sdF'><pre id='f1sdF'><center id='f1sdF'></center></pre></bdo></b><th id='f1sdF'></th></span></q></dt></tr></i><div id='f1sdF'><tfoot id='f1sdF'></tfoot><dl id='f1sdF'><fieldset id='f1sdF'></fieldset></dl></div>
              <bdo id='f1sdF'></bdo><ul id='f1sdF'></ul>

                本文介绍了检索和修改 XMLHttpRequest 的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在为 Firefox、Safari、Chrome 开发一个浏览器插件,它将拦截页面上的数据,针对正则表达式运行它,然后如果匹配 - 重新格式化它.我使用以下方法处理页面加载:

                I am working on a browser plugin for Firefox, Safari, Chrome that will intercept data on the page, run it against a regex and then if it matches - reformat it. I have this working on page load using:

                var meth = {
                  replaceInElement : function(element, find, replace) {
                        // iterate over child nodes and replace
                  },
                  run : function(evt){
                    // doc is the document that triggered "run" event
                    if (!(evt.target.nodeName === "#document")) { return; }
                    var doc = evt.target; // document that triggered "onload" event
                    if (!(doc instanceof HTMLDocument)) { return; }
                    if (!doc.location) { return; }
                
                    // perform substitutions on the loaded document
                    var find = /regex/gi
                
                    meth.replaceInElement(doc.body, find, function(match) {
                        var new_content;
                        //do stuff
                        return new_content;
                    });
                
                    //content.document.addEventListener('DOMNodeInserted', ezcall.node_inserted, false);
                  }
                }
                
                window.addEventListener("load", meth.run, false);
                

                这适用于静态页面,但对于使用 ajax 调用的任何内容,它都会失败.我找不到合适的侦听器或弄清楚如何拦截 XMLHttpRequest.

                This is working for static pages, but for anything using ajax calls, it fails. I cannot find the right listener or figure out how to intercept the XMLHttpRequest.

                我为 XMLHttpRequest 尝试了类似的事件侦听器,但没有成功.

                I have tried similar event listeners for XMLHttpRequest with no luck.

                XMLHttpRequest.addEventListener('load', meth.run, false);
                

                我想拦截请求并修改内容.或者找到更新的目标,在ajax调用完成后扫描.

                I would like to either intercept the request and modify the content. Or find the target that was updated and scan it after the ajax call is finished.

                更新:

                我会接受无法完成的回答,但我需要一些支持数据来说明为什么无法完成.

                I will accept an answer that says it cannot be done, but I will need some supporting data as to why it cannot be done.

                推荐答案

                比较脏但是你可以覆盖XMLHttpRequest.prototype.open.这是一个演示页面.由于您正在编写扩展程序,因此您必须将此代码放在页面上下文中:

                Rather dirty but you can overwrite XMLHttpRequest.prototype.open. Here is a Demo page. Since you're writing an extension, you must put this code in page context:

                (function() {
                    // save reference to the native method
                    var oldOpen = XMLHttpRequest.prototype.open;
                    // overwrite open with our own function
                    XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
                        // intercept readyState changes
                        this.addEventListener("readystatechange", function() {
                            // your code goes here...
                            console.log("Interception :) " + this.readyState);
                        }, false);
                        // finally call the original open method
                        oldOpen.call(this, method, url, async, user, pass);
                    };
                })();
                

                在这之后你可以做任何我猜的事情.替换 instance.readystatechange,替换 instance.addEventListener,或者监听突变事件(虽然它们是 已弃用).

                After this you can do anything I guess. Replace instance.readystatechange, replace instance.addEventListener, or listen to mutation events (although they are deprecated).

                这篇关于检索和修改 XMLHttpRequest 的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:为什么在调用 open throw 之前设置 XMLHttpRequest res 下一篇:是否可以从 beforeSend 回调中修改 XMLHttpRequest 数据

                相关文章

                最新文章

                <tfoot id='ESb4B'></tfoot>

                <small id='ESb4B'></small><noframes id='ESb4B'>

                1. <i id='ESb4B'><tr id='ESb4B'><dt id='ESb4B'><q id='ESb4B'><span id='ESb4B'><b id='ESb4B'><form id='ESb4B'><ins id='ESb4B'></ins><ul id='ESb4B'></ul><sub id='ESb4B'></sub></form><legend id='ESb4B'></legend><bdo id='ESb4B'><pre id='ESb4B'><center id='ESb4B'></center></pre></bdo></b><th id='ESb4B'></th></span></q></dt></tr></i><div id='ESb4B'><tfoot id='ESb4B'></tfoot><dl id='ESb4B'><fieldset id='ESb4B'></fieldset></dl></div>
                    <bdo id='ESb4B'></bdo><ul id='ESb4B'></ul>

                  1. <legend id='ESb4B'><style id='ESb4B'><dir id='ESb4B'><q id='ESb4B'></q></dir></style></legend>