0

我在这里找到了以下代码。如果我输入http://google.com

它将 google.com 加载到 iframe 中。

我的问题是,

  1. 我怎样才能填充超过 1 个 iframe

  2. 我可以拥有它,这样我就不必输入 http:// 只是域 google.com

谢谢,代码如下:

<html>
   <head>
      <title>Blah</title>
          <link href="style.css" rel="stylesheet" type="text/css"/>

             <script type="text/javascript">

               function SetSrc()
               {
                   document.getElementById("myIfreme").src = document.getElementById("txtSRC").value;
               }

            </script>
   </head>
<body>

<form>
     Enter URL:
     <input type="text" id="txtSRC" />
     <input type="button" value="GO" onclick="SetSrc()" />
</form>

     <iframe id="myIfreme" src="" frameborder="0" marginwidth="0" height="500" width="480">   
     </iframe>

     <iframe id="myIfreme" src="" frameborder="0" marginwidth="0" height="500" width="840"> 
     </iframe>

</body>
</html>

非常感谢。这正是我一直在寻找的!到这里就完成了:

<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css" />
<title>Blah</title>
<script type="text/javascript">
function SetSrc()
{
document.getElementById("myIfreme1").src = 'http://' +   
document.getElementById("txtSRC").value;
document.getElementById("myIfreme2").src = 'http://' + 
document.getElementById("txtSRC").value;
document.getElementById("myIfreme3").src = 'http://' + 
document.getElementById("txtSRC").value;
document.getElementById("myIfreme4").src = 'http://' + 
document.getElementById("txtSRC").value;
document.getElementById("myIfreme5").src = 'http://' + 
document.getElementById("txtSRC").value;
document.getElementById("myIfreme6").src = 'http://' + 
document.getElementById("txtSRC").value;

}
</script>
</head>
<body>
<form>
Enter URL:  http://
<input type="text" id="txtSRC" />
<input type="button" value="GO" onclick="SetSrc()" />
</form>
<div style="clear:both">320 width</div>
<iframe id="myIfreme1" src="" frameborder="0" marginwidth="0" height="480" width="320" 
scrolling="yes"></iframe>
<div style="clear:both">480 width</div>
<iframe id="myIfreme2" src="" frameborder="0" marginwidth="0" height="480" width="480" 
scrolling="yes"></iframe>
<div style="clear:both">640 width</div>
<iframe id="myIfreme3" src="" frameborder="0" marginwidth="0" height="480" width="640" 
scrolling="yes"></iframe>
<div style="clear:both">800 width</div>
<iframe id="myIfreme4" src="" frameborder="0" marginwidth="0" height="480" width="800" 
scrolling="yes"></iframe>
<div style="clear:both">1024 width</div>
<iframe id="myIfreme5" src="" frameborder="0" marginwidth="0" height="480" width="1024" 
scrolling="yes"></iframe>
<div style="clear:both">1280 width</div>
<iframe id="myIfreme6" src="" frameborder="0" marginwidth="0" height="480" width="1280"     
scrolling="yes"></iframe>

</body>
</html>

谢谢阿法辛-你太棒了!

4

1 回答 1

0

尝试:

<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css" />
<title>Blah</title>
<script type="text/javascript">
 function SetSrc()
 {
     document.getElementById("myIfreme1").src = document.getElementById("txtSRC").value;
     document.getElementById("myIfreme2").src = document.getElementById("txtSRC").value;
 }
</script>
</head>
<body>
<form>
Enter URL:
<input type="text" id="txtSRC" />
<input type="button" value="GO" onclick="SetSrc()" />
</form>
<iframe id="myIfreme1" src="" frameborder="0" marginwidth="0" height="500" width="480">
</iframe>
<iframe id="myIfreme2" src="" frameborder="0" marginwidth="0" height="500" width="840">
</iframe>

</body>
</html>

如果您不希望用户输入http://,您可以执行以下操作:

...
<form>
Enter URL:  http://
<input type="text" id="txtSRC" />
...

function SetSrc()
{
    document.getElementById("myIfreme1").src = 'http://' + document.getElementById("txtSRC").value;
    document.getElementById("myIfreme2").src = 'http://' + document.getElementById("txtSRC").value;
}

顺便说一句,谷歌会阻止你www.google.com在 iframe 中使用。

于 2013-06-25T04:39:52.557 回答