我在这里找到了以下代码。 如果我输入http://google.com
将google.com加载到iframe中。
我的问题是,
如何填充多个iframe
我可以拥有它,这样我就不必输入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>
感谢alfasin - 你太棒了!
答案 0 :(得分: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;
}
BTW,Google会阻止您在iframe中使用www.google.com
。