html+js代码|老版本调用随机链接

时间:2024-12-04 17:44:15   阅读:167

这是一个老版本还在用的代码,用了快有一年多,最近写了新的,就放出来。

  1. 创建tiaozhuan.js文件【链接改为自己的就可以】

// 使用立即执行函数来包装代码,用于提供封闭的命名空间和避免变量冲突
(function() {
// 定义函数,接收一个urls数组参数
function redirectToRandomUrl(urls) {
// 生成一个随机数,范围为0到urls数组长度-1
var randomIndex = Math.floor(Math.random() * urls.length);
// 将当前窗口的URL重定向到urls数组中随机索引对应的URL
window.location.href = urls[randomIndex];
}

// 定义一个包含多个URL的数组
var urls = [

//残痕
"https://mengbi.dfjsd.top",
"https://mengbi.oijsdfksa.top",
"https://mengbi.fgoikdgp.top",
"https://mengbi.mofa.pw",
"https://mengbi.sdfppkww.xyz",
"https://mengbi.zhifabaozhuang.cn"




];

// 检查浏览器是否支持window.location.href方式进行页面重定向
if (window.location && window.location.href) {
// 调用函数,将当前窗口的URL重定向到urls数组中随机索引对应的URL
redirectToRandomUrl(urls);
} else {
// 假定浏览器不支持上述方式时,使用location.replace方法进行页面重定向
// 生成一个随机数,范围为0到urls数组长度-1
var randomIndex = Math.floor(Math.random() * urls.length);
// 将当前窗口的URL替换为urls数组中随机索引对应的URL
location.replace(urls[randomIndex]);
}
})();

2.创建tiaozhuan.html文件,在里面放入调用js


<script type="text/javascript">

    document.write("<script src='/faka/tiaozhuan.js?"+Math.random()+"'><\/script>");

</script>


使用的时候是https://www.zshao.vip/tiaozhuan.html,这样就可以随机调用tiaozhuan.js里面的链接。

上一篇:php-html-js代码|一个新的思路调用TXT文件内的链接

下一篇:12月5日星期四,农历冬月初五,工作愉快,平安喜乐

网友评论