更改src属性后未重新加载iframe

时间:2019-02-23 04:01:45

标签: google-chrome iframe

我有完整的此代码,没有外部文件:

<style>
    .version-selection-scroll-panel {
        width: 15%;
        height: 100%;
        overflow-y: scroll;
    }

    .flex-container {
        display: flex;
    }

    .flex-vertical-container {
        display: flex;
        flex-direction: column;
    }

    html, body {margin: 0; height: 100%; overflow: hidden}

</style>

<script>

  const asyncc =  window.__asyncc__ = {};

  asyncc.latestVersion = 'v/0.1.0';

  asyncc.changeIframe = (versionPath) => {
    let iframe = document.getElementsByClassName("main-iframe");
    if(!iframe){
      return alert('Could not find iframe on page.');
    }

    console.log('src:', versionPath);
    iframe.src = versionPath;

    console.log({iframe});
    // iframe.replaceWith(iframe);
    // iframe.location.reload();
    // iframe.contentWindow.location.reload();
  };


</script>

<div class="flex-container">

    <div class="version-selection-scroll-panel">
        <div class="flex-vertical-container">
            <button onclick="asyncc.changeIframe('v/0.1.0')">version 0.1.1</button>
            <button onclick="asyncc.changeIframe('v/0.1.2')">version 0.1.2</button>
            <button onclick="asyncc.changeIframe('v/0.1.3')">version 0.1.3</button>
        </div>
    </div>
    <div style="display: flex; flex-grow: 1">
        <iframe id="main-iframe" src="v/0.1.0" width="100%" height="100%"></iframe>
    </div>
</div>

更改iframe.src属性后,不会发生任何事情。我也尝试致电:

iframe.contentWindow.location.reload();

,但不存在contentWindow属性。我正在Chrome:72.0.3626.109版(正式版本)(64位)上运行此程序

0 个答案:

没有答案