我試圖使用Javascript函數在名爲「cake」的iframe中加載網頁。我怎樣才能做到這一點?使用JavaScript函數在iFrame中加載頁面
<html>
<head>
</head>
<body>
<button onclick=[function]>Load page in iframe</a>
</body>
</html>
我試圖使用Javascript函數在名爲「cake」的iframe中加載網頁。我怎樣才能做到這一點?使用JavaScript函數在iFrame中加載頁面
<html>
<head>
</head>
<body>
<button onclick=[function]>Load page in iframe</a>
</body>
</html>
function changeUrl() {
var site = "http://www.w3schools.com";
document.getElementsByName('iFrameName')[0].src = site;
}
<html>
<head>
</head>
<body>
<button onclick="changeUrl()">Load page in iframe</button>
<iframe name="iFrameName"></iframe>
</body>
</html>
這工作:
<html>
<head>
<script type="text/javascript">
function changeUrl() {
var site = "1.wav";
document.getElementsByName('cake')[0].src = site;
}
</script>
</head>
<body>
<center>
<iframe src="http://www.w3schools.com" height=400 width=400 frameborder=0 name = "cake" style =""></></iframe>
<br>
<br>
<button onclick="changeUrl()">Load page in iframe</button>
</center>
</body>
</html>
似乎有不爲'在iframe'名爲 「蛋糕」 的HTML,但是一般來說,'document.frames ['cake']。location.href = what_ever;'。或者爲'iframe'提供'id'並且說'document.getElementById('iframe_id')。src ='what_ever';'。也建議熟悉[你正在使用的元素](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe)... – Teemu
我知道,製作一個名爲「蛋糕」的iframe是我想要(打算)製作的。 – MistaBoodadee
你在問如何訪問一個iframe,而不是如何創建一個... – Teemu