0

我正在创建一个跟踪工具,记录按钮从任何域单击到数据库。

我想使用 Web Workers,但支持此功能的浏览器列表有限,所以...我添加了浏览器检测以将它们发送到正确的路径。

我的问题是,一旦我将浏览器检测添加到 IE,我不再得到服务器响应,(发布,重定向,什么都没有)我做错了什么吗?

这是检测按钮的地方

            if ((isIE) && (isIE == true)) {

            function addBtnClickListener(e) {
                var btnClicked = this;

                var eventType = "button.click";
                var ctrBtnText = btnClicked.value;
                track(btnClicked, eventType, '', '', ctrBtnText, '', '', '', btnClicked);

                return false;
            }
        }
        else if ((isChrome) && (isChrome == true) || (isFirefox) && (isFirefox == true) || (isSafari) && (isSafari == true) || (isOpera) && (isOpera == true)) {
            //WEB WORKERS
            if (typeof SharedWorker != 'undefined') { //shared web worker is supported

                //Shared Worker
                function addBtnClickListener() {
                    var btnClicked = this;

                    var eventType = "button.click";
                    var ctrBtnText = btnClicked.value;
                    track(btnClicked, eventType, '', '', ctrBtnText, '', '', '', null, btnClicked);

                    return false;
                }
            }

            else if (typeof (Worker) != "undefined") { //web worker is supported

                //Web Worker
                function addBtnClickListener(e) {
                    e.preventDefault();
                    var btnClicked = this;

                    var eventType = "button.click";
                    var ctrBtnText = btnClicked.value;
                    track(btnClicked, eventType, '', '', ctrBtnText, '', '', '', btnClicked, null);
                    //this.click();
                    return true;
                }
            }

            else {
                //function addBtnClickListener(e) {
                var btnClicked = this;

                var eventType = "button.click";
                var ctrBtnText = btnClicked.value;
                track(btnClicked, eventType, '', '', ctrBtnText, '', '', '', btnClicked);

                return false;
                //}
            }
        }
        else { }

这是他们被记录的地方

        if ((isIE) && (isIE == true)) {

            console.log("IE");

            doRequestMethod(url);

            function GetXmlHttpObject() {
                if (window.XMLHttpRequest) {
                    //for IE7+, Firefox, Chrome, Opera, Safari
                    return new XMLHttpRequest();
                }
                if (window.ActiveXObject) {
                    //for IE6, IE5
                    return new ActiveXObject("Microsoft.XMLHTTP");
                }
                return null;
            }

            function doRequestMethod(url) {
                var xmlhttp = GetXmlHttpObject();
                if (xmlhttp == null) {
                    console.log("Browser does not support HTTP Request");
                    return;
                }
                xmlhttp.open("POST", url, true);
                xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                xmlhttp.send(url);
            }

        }
        else if ((isChrome) && (isChrome == true) || (isFirefox) && (isFirefox == true) || (isSafari) && (isSafari == true) || (isOpera) && (isOpera == true)) {

            //WORKS AS IT SHOULD

        }
        else { }

删除 IE 检测检测后,表单在 IE 中正常工作,我做错了吗?

4

0 回答 0