最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why does the `history.length` of the main application increase due to the `history.pushState()` method being called

programmeradmin1浏览0评论

these are main app & sub app below, Why does the history.length of the main application increase due to the history.pushState() method being called within the iframe?

<!DOCTYPE html>
<html>

<body>
  <div id="app">{{ message }}</div>
  <iframe src="http://127.0.0.1:5501/iframe-page2.html" id="iframe2"></iframe>

  <!-- Vue2 的 CDN -->
  <script src="/[email protected]"></script>
  <script>
    new Vue({
      el: "#app",
      data: {
        message: "Main(Vue2)"
      },
    });

    window.addEventListener("popstate", (event) => {
      console.log("【main app】:", event, window.history.length);
    });
  </script>
</body>

</html>


<!DOCTYPE html>
<html>

<body>
  <div id="app">{{ message }}</div>

  <!-- Vue3 的 CDN -->
  <script src="/[email protected]/dist/vue.global.js"></script>
  <script>
    const app = Vue.createApp({
      data() {
        return {
          message: "Iframe(Vue3)"
        };
      },
    });

    setTimeout(() => {
      console.log("before history.length, ", history.length, history.state);
      history.pushState({
        test2: 222
      }, "", "test222");
      console.log("after history.length, ", history.length, history.state);
    }, 20000);

    app.mount("#app");

    window.addEventListener("popstate", (event) => {
      console.log("【sub app】:", event);
    });
  </script>
</body>

</html>

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论