我尝试通过 iframe 在 html 页面中创建一个迷你浏览器:
<table id="frame" height="100%" width="100%" border="0">
<tr>
<td>Enter the address:
<label for="address"></label>
<input type="text" name="address" id="address">
<input type="submit" name="go" id="go" value="Go"></td>
</tr>
<tr>
<td><iframe src="http://www.google.com" width="100%" height="100%"></iframe></td>
</tr>
</table>
但我不知道如何获取地址值并代替 google.com,如何使用 html 或 javascript 做到这一点?
最佳答案
您可以使用 id
从 Javascript 设置 src
属性来检索 iframe
节点。
Address: <input id="address">
<input type="button" value="go" onclick="visit()">
<br>
<iframe id="my_iframe"></iframe>
<script>
function visit() {
var address = document.getElementById("address").value;
document.getElementById("my_iframe").src = address;
}
</script>
但请注意,有大量网站不允许您以这种方式访问它们。原因很复杂(在我看来有些愚蠢),但重点仍然是它不是一种可以普遍使用的技术。
关于javascript - 使用 iframe 浏览互联网,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19031234/