将一个随机数放入 iframe src URL



我想要一个随机数在?i=后面

<li>
<strong>&nbsp; &nbsp;Clip</strong>&nbsp;2<br>
<iframe src="https://mysite.ml/links/clip2.html?i=" height="350" width="600" frameborder="0" scrolling="no" allowfullscreen="true"></iframe>
</li>

首先,确保您的iframe具有id属性,例如:

<iframe id="myrandomiframe" src="" height="350" width="600" frameborder="0" scrolling="no" allowfullscreen="true"></iframe>

然后onpageload,使用 JavaScript 设置附加Math.random()src属性,例如:

document.getElementById("myrandomiframe").setAttribute("src","https://mysite.ml/links/clip2.html?i=" + Math.random());

当页面加载时,你必须这样做。

window.addEventListener('load', function(){
document.getElementsByTagName("iframe")[0].src += rando(Number.MAX_SAFE_INTEGER);
console.log(document.getElementsByTagName("iframe")[0].src);
});
<script src="https://randojs.com/1.0.0.js"></script>
<iframe src="example.com/?i="></iframe>

如果你需要深入研究其中任何一个,我用 randojs.com 在0和Number.MAX_SAFE_INTEGER之间选择一个数字。

最新更新