代码之家  ›  专栏  ›  技术社区  ›  Vikash

更改父窗口iframe的src

  •  -3
  • Vikash  · 技术社区  · 5 年前

    https://example.com 我已经在其中加载了iframe,其中包含src https://example2.com/iframe

    https://example3.com . 所以示例3不允许在Iframe内部打开,所以我的代码失败了。

    https://example3.com 在另一个窗口中,如果要执行某些操作,请关闭该窗口。接下来,我将回到 (iframe已加载的网站)并希望将一个参数添加到iframe的src中,以便我可以确定我已完成了 https://example3.com 并希望更改和重新加载Iframe的src。

    请随时添加评论,以防我可以帮助您更好地理解我的问题。

    1 回复  |  直到 5 年前
        1
  •  1
  •   charlietfl    5 年前

    因为听起来好像你不能在新窗口中控制站点上的代码,所以你能做的唯一实际的事情就是设置一个间隔来检查你打开的新窗口是否正确 window.open()

    然后,在确定它已关闭后,为用户添加某种提示

    var otherWindow = window.open('example3.com');
    
    var timer = setInterval(function(){
       if(otherWindow.closed){
          clearInterval(timer);
          if(confirm('Did you complete that step?')){
            // adjust iframe url
          }
       }
    },1000);// check every second if it is closed