使用javascript函数在iFrame中加载页面
问题描述:
我正在尝试使用Javascript函数在名为cake的iframe中加载网页。我怎样才能做到这一点?
I'm trying to use a Javascript function to load a web page in an iframe named "cake". How can I do that?
<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>