文档.IE中的url问题

document.url issue in IE

本文关键字:问题 url 中的 IE 文档      更新时间:2023-09-26
function drawCaptcha() {
    var absURL = document.URL.substr(0, document.URL.lastIndexOf('#'));
     // Internet Explorer 6-11
    var isIE = /*@cc_on!@*/false || !!document.documentMode;
        // Edge 20+
    var isEdge = !isIE && !!window.StyleMedia;
    if(isIE || isEdge){
        var absURL = window.location.href.substr(0, window.location.href.lastIndexOf('#'));
    }
    console.log("absURL==",absURL);
    document.getElementById('captchaImage').setAttribute('src',
            absURL + 'web/gencptch');
    //document.getElementById('captchaImage').setAttribute('src', '/epa-web/web/gencptch');
}

嗨我试图通过点击按钮生成验证码图像。它在chrome和Mozilla中可以完美地工作,但在IE中存在问题。

当我试图在IE中调试时,我发现了文档的值。URL与chrome和Mozilla不同

在chrome中它的值是localhost:8080/login/#,在IE中它的值是" "。我试着用window.location.href代替document.URL,但是没有运气。我努力尝试,但没有得到为什么图像不显示在IE的原因。在网络部分,我看到服务没有被调用,不知道为什么!!

EDIT:-

这个问题是由于JQuery

因为当我加载页面时,我调用了一个函数

$(document).ready(
            function() {
                var absURL = document.URL.substr(0, document.URL
                        .lastIndexOf('#'));
                document.getElementById('captchaImage').setAttribute('src',
                        absURL + 'web/gencptch');
            });

任何帮助都是感激的!

谢谢

不知道你在做什么…

function drawCaptcha() {
    document.getElementById('captchaImage').setAttribute('src','test');
    var urlHash = location.href.lastIndexOf('#');
    if ( urlHash === -1 ) urlHash = location.href.length;
    var absURL = location.href.substr(0, urlHash);
    document.getElementById('captchaImage').setAttribute('src',
            absURL + 'web/gencptch');
}

这应该可以正常工作。请确保您确实调用了drawCaptcha()

location.href在所有浏览器中都是强已知位置。

我这里有一个例子。我在Windows 10上测试了IE"Edge"(v11,可执行v11.1000.14931.0)以及Windows 10上的Microsoft Edge (v14,可执行v11.0.14931.1000)。检查元素,src属性在几个给定的场景中是正确的。