javascript - 使用 JavaScript 获取 url 参数的站点加载时间
问题描述
访问domain.com?site=www.google.com时加载时出错,似乎时间是随机的。
代码:
<html>
<head><p>Website Checker</p>
<script type='text/javascript'>
function checkhowlongittakes() {
weburl = "<?php echo $_GET['site']; ?>";
getLoadTime(weburl, function(time) {
document.write('load time for ' + weburl + ' was >' + time + 'ms');
});
}
function getLoadTime(url, callback) {
var req = new XMLHttpRequest();
var start = Date.now();
req.onreadystatechange = function(e) {
if (this.readyState == 4)
callback(Date.now() - start);
}
req.open('GET', url);
req.send();
}
</script>
</head>
<body onload="checkhowlongittakes()">
</body>
</html>
解决方案
推荐阅读
- angular - 在 Angular 模板中访问联合类型的属性
- ios - 在连接到 Focusrite 2i2 的 AKFrequencyTracker 上获得奇怪的频率读数
- reactjs - React useState hook - 更新状态时何时使用先前的状态?
- android - 如何在 Android Studio 上使用应用内购买销售图片
- scala - 单位类型的所有值都可以用单位创建吗?
- google-chrome - Pyppeteer 超时后查询页面内容?
- git - 在分离头时将多个提交放入新分支
- flutter - Flutter Extract Method vs. Extract Widget vs. 在androidStudio中提取Flutter Widget
- javascript - TypeScript:为什么我的过滤方法无法缩小类型并从数组中消除未定义和错误
- ios - 修复警告:无法在 (Project.UnderlinedTextField) 上设置 (lineColor) 用户定义的检查属性