ifream嵌入不同源頁面 子頁面與父頁面交互

父頁面:(app.vue)

    let _this = this
    window.onload = function () {
      window.addEventListener('message', function (e) {
        let prefix = "openTab:"
        if (e.data && (typeof e.data == "string") && e.data.startsWith(prefix)) {
          let routerPath = e.data.substring(prefix.length)
          _this.$router.push({ path: routerPath });
        }
      })
    }

子頁面:

   <script type="text/javascript">
      function test(){
        let routerPath = "/dashboard"
        window.parent.postMessage("openTab:" + routerPath, "*");
      }
    </script>
    
   <button type="button" onclick="test()">測試</button>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章