doumi9618 2015-03-11 16:45
浏览 61
已采纳

创建插件来检测可疑的ajax

I want to make browser extension for Firefox that detect the ajax code of of website that load the hidden page and redirect to new page ,like if user visit index.php where ajax load the two pages one is hiddenpage.php and redirect to new.php . Is there any other solution to detect this ajax at client side.

if (xmlhttp.readyState==4 && xmlhttp.status==200)
                {
                    //document.getElementById("myDiv").innerHTML="";
                }
            }
            xmlhttp.open("GET","hidden.php",true);
            xmlhttp.send();
        }

HTML

<a href="new.php" onclick="function();">click here</a>
  • 写回答

2条回答 默认 最新

  • doubeishuai6598 2015-03-14 15:09
    关注
    document.addEventListener('DOMContentLoaded', function() {
        getCurrentTabUrl(function(url) {
            fetchData(url);
        });
    });
    
    function fetchData(url)
    {
        var xhr = new XMLHttpRequest();
        xhr.open("GET", url, true);
        xhr.onreadystatechange=function()
        {
            if (xhr.readyState==4 && xhr.status==200)
            {
                var data = xhr.responseText;
                var  index = data.indexOf('XMLHttpRequest');
                if(index != -1){
                    document.getElementById("status").innerHTML = "The page contains AJAX requests";
                }else{
                    document.getElementById("status").innerHTML = "Page doesn't contains AJAX";
                }
                //document.getElementById("status").innerHTML = data;
            }
        }
        //xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        //xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
        //xhr.setRequestHeader("Access-Control-Request-Method", "POST");
        xhr.send();
    }
    
    function getCurrentTabUrl(callback) {
        var queryInfo = {
        active: true,
        currentWindow: true
        };
        chrome.tabs.query(queryInfo, function(tabs) {
            var tab = tabs[0];
            var url = tab.url;
            console.assert(typeof url == 'string', 'tab.url should be a string');
            callback(url);
        });
    }
    just go through this code you will get the better help
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog