可以自动填充文本字段以进行嵌入网络的互联网速度测试吗?

问题描述 投票:0回答:1

OpenSpeedTest 提供 HTML5 代码以在网页中嵌入速度测试小部件。我已经为我的网站实现了这一点,但是没有 API 来获取结果并自动填充我的文本字段。显然我也无法使用 Javascript 访问跨域框架,所以我不知道该怎么办。 Speedtest Ookla 不再具有可访问的 API 来执行此操作,因此我不确定这里还有哪些其他选项。

<script>
    function getSpeedTestResults() {
        // Attempt to access the iframe content
        let iframe = document.getElementById('speedtest');
        let iframeContent = iframe.contentDocument || iframe.contentWindow.document;

        // Attempt to access the results inside the iframe (this will likely be blocked)
                let downloadSpeed = iframeContent.getElementById('downResult').textContent;
        let uploadSpeed = iframeContent.getElementById('upRestxt').textContent;
        let ping = iframeContent.getElementById('pingResult').textContent;

        // Set the values in your fields
        document.getElementById('download').value = downloadSpeed;
        document.getElementById('upload').value = uploadSpeed;
        document.getElementById('ping').value = ping;
    }
</script>
javascript iframe autofill speed-test
1个回答
0
投票

您可以自行托管一个,这里是一个示例: 免费开源自托管 HTML5 SpeedTest

唯一的缺点:您必须自己托管速度测试服务器,在随附的链接中您会获得有关如何执行此操作的说明。

希望这有帮助

© www.soinside.com 2019 - 2024. All rights reserved.