0

javascript ランダマイザのランダム URL のリストから iframe のソースを変更するにはどうすればよいですか。js、html、またはcssのいずれかを使用したい

以下のソース コードは、リストからランダムな Web サイトにリンクする現在の Web サイトのものです。リンク先のリンクは、戻るボタンなどを含むボックスと同じ形式のページに保持したいと考えています。

私のウェブサイト: 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で選択されたURLをiframeすることです。

私のウェブサイトのソースコード全体は次のとおりです。

<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>

事前にご協力いただきありがとうございます。これは本当に役立ちます

4

1 に答える 1

0

私の理解が正しければ、URL を iframe にロードし、選択した URL を Web サイトのどこかに表示する必要があります。

関数を次のように変更します。

<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>
于 2013-07-15T13:16:20.427 に答える