在提供的代码中,没有找到会触发弹窗打开的相关逻辑。需要在获取版本号的逻辑中判断是否有新版本,并在条件成立时打开弹窗。

下面是修改的示例代码:

// 获取版本号函数
function getVersion() {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'http://ry91f4dqi.hb-bkt.clouddn.com/versionapp.txt', true);

    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4 && xhr.status === 200) {

            var latestVersion = xhr.responseText; // 获取最新版本号
            var currentVersion = "2.5.0.0"; // 当前版本号,可根据实际情况修改

            if (latestVersion !== currentVersion) { // 判断是否有新版本
                openPopup(latestVersion, currentVersion); // 打开弹窗
            }
        }
    };

    xhr.send();
}

// 打开弹窗函数
function openPopup(latestVersion, currentVersion) {
    var updatePopup = document.getElementById('updatePopup');
    var updateContent = document.getElementById('updateContent');

    updateContent.innerHTML = "当前版本:" + currentVersion + "<br>最新版本:" + latestVersion;
    updatePopup.classList.add('open');
}

// 页面加载完成后调用
window.onload = function() {
    getVersion();
}

在上述代码中,通过获取版本号文件的内容并与当前版本进行比较,判断是否有新版本。如果有新版本,调用openPopup()函数打开弹窗,并将最新版本号和当前版本号作为参数传递给弹窗内容

!DOCTYPE htmlhtmlhead titleUI设计示例title meta name=viewport content=width=device-width initial-scale=1 style body background-color #E0F5FF; font-family Arial sans-

原文地址: https://www.cveoy.top/t/topic/iBoA 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录