如果iframe网址发生更改,请更改父框架网址

时间:2016-11-20 08:45:16

标签: javascript jquery html iframe

我有一个页面:

<iframe src="http://externalwebsite.com/test.html" scrolling="no" height="400px" width="400px" allowfullscreen></iframe>

如果iframe网址更改为http://mywebsite.com/succes.html,我想将父网址更改为http://externalwebsite.com/succes.html

我试图用JavaScript解决这个问题,但我没有设法做到这一点。有人能帮我吗?

1 个答案:

答案 0 :(得分:0)

<iframe id="frameId" src="http://externalwebsite.com/test.html" scrolling="no" height="400px" width="400px" allowfullscreen></iframe>

绑定到父窗口中的frame.onload事件。

var frame = document.getElementById('frameId'); 
frame.onload = function(e){
   if(frame.src === 'http://externalwebsite.com/succes.html' ){
      window.location.href = 'http://externalwebsite.com/succes.html';
   }
};

尝试frame.src='someUrl';进行测试。

相关问题