使用javascript函数在iFrame中加载页面

Mis*_*dee 8 javascript iframe

我正在尝试使用Javascript函数在名为"cake"的iframe中加载网页.我怎样才能做到这一点?

<html>
  <head>
  </head>
  <body>
    <button onclick=[function]>Load page in iframe</a>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

San*_*ria 16

function changeUrl() {
    var site = "http://www.w3schools.com";
    document.getElementsByName('iFrameName')[0].src = site;
}
Run Code Online (Sandbox Code Playgroud)
    <html>
      <head>
      </head>
        <body>
          <button onclick="changeUrl()">Load page in iframe</button>
          <iframe name="iFrameName"></iframe>
        </body>
    </html>
Run Code Online (Sandbox Code Playgroud)

  • 厕所..:)..你能投票一下吗..我想赢得一些声誉..这样我就可以贡献更多..:) (2认同)