如何使用javascript Randomizer脚本链接到iframe,以便我可以从脚本中的链接列表中打开

How to use a javascript Randomizer script to link into an iframe so that i can open from a list of links in the script

本文关键字:链接 脚本 我可以 列表 javascript 何使用 Randomizer iframe      更新时间:2023-09-26

如何从javascript随机化器中的随机url列表更改iframe的源。我很想使用js或html或css

下面的源代码是我当前网站的,它将你从列表中链接到一个随机网站,我想将它链接到的链接保存在一个页面中,该页面的格式与带有后退按钮等的框相同。

我的网站:http://www.boredombutton.co.uk

下面是我的代码的一部分:

<script type="text/javascript">
var url=[
'http://www.fallingfalling.com',
'http://www.omfgdogs.com',
];
window.onload=function()
{document.getElementById('trig').onclick=function(){
location.href=url[Math.floor(Math.random()*url.length)];}}
</script>

我想做的是iframe,在同一个iframe中选择的url可以互换。

我的网站的全部源代码如下:

<html>
<head>
<title>BoredomButton</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<script type="text/javascript">
var url=[
'http://www.fallingfalling.com',
'http://www.omfgdogs.com',
'http://www.republiquedesmangues.fr',
'http://www.staggeringbeauty.com',
'http://ducksarethebest.com',
'http://eelslap.com',
'http://heeeeeeeey.com',
'http://breakglasstosoundalarm.com'

];
window.onload=function()
{document.getElementById('trig').onclick=function(){
location.href=url[Math.floor(Math.random()*url.length)];}}
</script>
<body align="center"  bgcolor="#egegeg" leftmargin="0" topmargin="0" marginwidth="0"      marginheight="0">


<table align="center" id="Table_01" width="968" height="650" border="0" cellpadding="0"    cellspacing="0">
<tr>
    <td colspan="3">
        <img src="images/BoredomButton_01.png" width="968" height="363"       alt=""></td>
</tr>
<tr>
    <td rowspan="2">
        <img src="images/BoredomButton_02.png" width="347" height="287" alt=""></td>
    <td>
        <a href="#" id="trig"><img src="images/BoredomButton_03.png" width="274" height="99" alt=""></td>
    <td rowspan="2">
        <img src="images/BoredomButton_04.png" width="347" height="287" alt=""></td>
</tr>
<tr>
    <td>
        <img src="images/BoredomButton_05.png" width="274" height="188" alt=""></td>
</tr>
</table>

</body>
</html>

感谢您提前提供的帮助,这将真正帮助

如果我理解正确,你想在iframe中加载URL,会在网站上的某个地方显示所选的URL。

将您的功能更改为:

<script type="text/javascript">
var url=[
    'http://www.fallingfalling.com',
    'http://www.omfgdogs.com',
];
window.onload=function() {
    var theURL = url[Math.floor(Math.random()*url.length)];
    document.getElementById('trig').onclick=function() {
        location.href=theURL;
    }}
    document.getElementById('chosenURL').innerHTML = '<a href="'+theURL+'">'+theURL+'</a>';
</script>

然后将这个HTML添加到你的页面中,在那里你想要文本:

<div id="chosenURL"></div>